/* Generated by Cython 0.22 */

#define PY_SSIZE_T_CLEAN
#ifndef CYTHON_USE_PYLONG_INTERNALS
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 0
#else
#include "pyconfig.h"
#ifdef PYLONG_BITS_IN_DIGIT
#define CYTHON_USE_PYLONG_INTERNALS 1
#else
#define CYTHON_USE_PYLONG_INTERNALS 0
#endif
#endif
#endif
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
    #error Cython requires Python 2.6+ or Python 3.2+.
#else
#define CYTHON_ABI "0_22"
#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
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
#define CYTHON_COMPILING_IN_PYPY 1
#define CYTHON_COMPILING_IN_CPYTHON 0
#else
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_CPYTHON 1
#endif
#if CYTHON_COMPILING_IN_PYPY && 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_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyType_Type
#endif
#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_VERSION_HEX < 0x030400a1 && !defined(Py_TPFLAGS_HAVE_FINALIZE)
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ? \
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
#else
  #define CYTHON_PEP393_ENABLED 0
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
  #define __Pyx_PyFrozenSet_Size(s)         PyObject_Size(s)
#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))
  #define __Pyx_PyFrozenSet_Size(s)         PySet_Size(s)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif
#if PY_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
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_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   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  /* Initialize NaN. The sign is irrelevant, an exponent with all bits 1 and
   a nonzero mantissa means NaN. If the first bit in the mantissa is 1, it is
   a quiet NaN. */
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif
#define __Pyx_void_to_None(void_result) (void_result, Py_INCREF(Py_None), Py_None)
#ifdef __cplusplus
template<typename T>
void __Pyx_call_destructor(T* x) {
    x->~T();
}
template<typename T>
class __Pyx_FakeReference {
  public:
    __Pyx_FakeReference() : ptr(NULL) { }
    __Pyx_FakeReference(T& ref) : ptr(&ref) { }
    T *operator->() { return ptr; }
    operator T&() { return *ptr; }
  private:
    T *ptr;
};
#endif


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

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

#if defined(WIN32) || defined(MS_WINDOWS)
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#define __PYX_HAVE__pysam__calignmentfile
#define __PYX_HAVE_API__pysam__calignmentfile
#include "stdint.h"
#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "sys/types.h"
#include "zlib.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 "pysam_stream.h"
#include "htslib/faidx.h"
#include "htslib/tbx.h"
#include "htslib/vcf.h"
#include "samfile_util.h"
#include "pythread.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (    \
    (sizeof(type) < sizeof(Py_ssize_t))  ||             \
    (sizeof(type) > sizeof(Py_ssize_t) &&               \
          likely(v < (type)PY_SSIZE_T_MAX ||            \
                 v == (type)PY_SSIZE_T_MAX)  &&         \
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||       \
                                v == (type)PY_SSIZE_T_MIN)))  ||  \
    (sizeof(type) == sizeof(Py_ssize_t) &&              \
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||        \
                               v == (type)PY_SSIZE_T_MAX)))  )
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(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_PyObject_AsSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((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)
#if PY_MAJOR_VERSION < 3
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
{
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#else
#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen
#endif
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_Owned_Py_None(b) (Py_INCREF(Py_None), Py_None)
#define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
#if CYTHON_COMPILING_IN_CPYTHON
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    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));
    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 PyObject *__pyx_m;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


static const char *__pyx_f[] = {
  "pysam/calignmentfile.pyx",
  "pysam/calignmentfile.pxd",
  "array.pxd",
  "pysam/cfaidx.pxd",
  "type.pxd",
  "bool.pxd",
  "complex.pxd",
};

/*--- Type declarations ---*/
#ifndef _ARRAYARRAY_H
struct arrayobject;
typedef struct arrayobject arrayobject;
#endif
struct __pyx_obj_5pysam_6cfaidx_FastaFile;
struct __pyx_obj_5pysam_6cfaidx_FastqProxy;
struct __pyx_obj_5pysam_6cfaidx_FastxFile;
struct __pyx_obj_5pysam_6cfaidx_FastqFile;
struct __pyx_obj_5pysam_6cfaidx_Fastafile;
struct __pyx_obj_5pysam_6cfaidx_Fastqfile;
struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment;
struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile;
struct __pyx_obj_5pysam_14calignmentfile_PileupColumn;
struct __pyx_obj_5pysam_14calignmentfile_PileupRead;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRow;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs;
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection;
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn;
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion;
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs;
struct __pyx_obj_5pysam_14calignmentfile_IndexedReads;
struct __pyx_obj_5pysam_14calignmentfile_SNPCall;
struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr;
struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr;
struct __pyx_t_5pysam_14calignmentfile___iterdata;
typedef struct __pyx_t_5pysam_14calignmentfile___iterdata __pyx_t_5pysam_14calignmentfile___iterdata;
struct __pyx_opt_args_5pysam_14calignmentfile_14AlignedSegment_set_tag;
struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData;
struct __pyx_opt_args_5pysam_14calignmentfile__get_value_code;
struct __pyx_opt_args_5pysam_14calignmentfile__get_value_type;

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

/* "pysam/calignmentfile.pxd":75
 *     # 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=?)             # <<<<<<<<<<<<<<
 * 
 *     # add an alignment tag with value to the AlignedSegment
 */
struct __pyx_opt_args_5pysam_14calignmentfile_14AlignedSegment_set_tag {
  int __pyx_n;
  PyObject *value_type;
  PyObject *replace;
};

/* "pysam/calignmentfile.pxd":188
 *     cdef char * getSequence( self )
 *     cdef setMask(self, mask)
 *     cdef setupIteratorData(self,             # <<<<<<<<<<<<<<
 *                            int tid,
 *                            int start,
 */
struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData {
  int __pyx_n;
  int multiple_iterators;
};

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

/* "pysam/calignmentfile.pyx":2249
 * 
 * 
 * cdef inline _get_value_type(value, maximum_value=None):             # <<<<<<<<<<<<<<
 *     '''returns the value type of a value.
 * 
 */
struct __pyx_opt_args_5pysam_14calignmentfile__get_value_type {
  int __pyx_n;
  PyObject *maximum_value;
};

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


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


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


/* "cfaidx.pxd":34
 * 
 * # Compatibility Layer for pysam 0.8.1
 * cdef class FastqFile(FastxFile):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_6cfaidx_FastqFile {
  struct __pyx_obj_5pysam_6cfaidx_FastxFile __pyx_base;
};


/* "cfaidx.pxd":38
 * 
 * # Compatibility Layer for pysam < 0.8
 * cdef class Fastafile(FastaFile):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_6cfaidx_Fastafile {
  struct __pyx_obj_5pysam_6cfaidx_FastaFile __pyx_base;
};


/* "cfaidx.pxd":41
 *     pass
 * 
 * cdef class Fastqfile(FastxFile):             # <<<<<<<<<<<<<<
 *     pass
 */
struct __pyx_obj_5pysam_6cfaidx_Fastqfile {
  struct __pyx_obj_5pysam_6cfaidx_FastxFile __pyx_base;
};


/* "pysam/calignmentfile.pxd":68
 * #
 * # Note: need to declare all C fields and methods here
 * cdef class AlignedSegment:             # <<<<<<<<<<<<<<
 * 
 *     # object that this AlignedSegment represents
 */
struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignedSegment *__pyx_vtab;
  bam1_t *_delegate;
};


/* "pysam/calignmentfile.pxd":84
 *     cpdef has_tag(self, tag)
 * 
 * cdef class AlignmentFile:             # <<<<<<<<<<<<<<
 * 
 *     cdef object _filename
 */
struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignmentFile *__pyx_vtab;
  PyObject *_filename;
  htsFile *htsfile;
  hts_idx_t *index;
  bam_hdr_t *header;
  int is_bam;
  int is_cram;
  int is_stream;
  int is_remote;
  bam1_t *b;
  char *mode;
  int64_t start_offset;
};


/* "pysam/calignmentfile.pxd":120
 *     cdef char * _getrname(self, int tid)
 * 
 * cdef class PileupColumn:             # <<<<<<<<<<<<<<
 *     cdef bam_pileup1_t ** plp
 *     cdef int tid
 */
struct __pyx_obj_5pysam_14calignmentfile_PileupColumn {
  PyObject_HEAD
  bam_pileup1_t **plp;
  int tid;
  int pos;
  int n_pu;
};


/* "pysam/calignmentfile.pxd":126
 *     cdef int n_pu
 * 
 * cdef class PileupRead:             # <<<<<<<<<<<<<<
 *     cdef AlignedSegment _alignment
 *     cdef int32_t  _qpos
 */
struct __pyx_obj_5pysam_14calignmentfile_PileupRead {
  PyObject_HEAD
  struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *_alignment;
  int32_t _qpos;
  int _indel;
  int _level;
  uint32_t _is_del;
  uint32_t _is_head;
  uint32_t _is_tail;
  uint32_t _is_refskip;
};


/* "pysam/calignmentfile.pxd":136
 *     cdef uint32_t _is_refskip
 * 
 * cdef class IteratorRow:             # <<<<<<<<<<<<<<
 *     cdef int retval
 *     cdef bam1_t * b
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRow {
  PyObject_HEAD
  int retval;
  bam1_t *b;
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *samfile;
  htsFile *htsfile;
  bam_hdr_t *header;
  int owns_samfile;
};


/* "pysam/calignmentfile.pxd":144
 *     cdef int owns_samfile
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef hts_itr_t * iter
 *     cdef bam1_t * getCurrent( self )
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion *__pyx_vtab;
  hts_itr_t *iter;
};


/* "pysam/calignmentfile.pxd":149
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowHead(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int max_rows
 *     cdef int current_row
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowHead *__pyx_vtab;
  int max_rows;
  int current_row;
};


/* "pysam/calignmentfile.pxd":155
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam1_t * getCurrent( self )
 *     cdef int cnext(self)
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowAll *__pyx_vtab;
};


/* "pysam/calignmentfile.pxd":159
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowAllRefs(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int         tid
 *     cdef IteratorRowRegion rowiter
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow __pyx_base;
  int tid;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *rowiter;
};


/* "pysam/calignmentfile.pxd":163
 *     cdef IteratorRowRegion rowiter
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef int current_pos
 *     cdef positions
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowSelection *__pyx_vtab;
  int current_pos;
  PyObject *positions;
};


/* "pysam/calignmentfile.pxd":169
 *     cdef int cnext(self)
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 * 
 *     # result of the last plbuf_push
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn *__pyx_vtab;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *iter;
  int tid;
  int pos;
  int n_plp;
  int mask;
  bam_pileup1_t *plp;
  bam_plp_t pileup_iter;
  __pyx_t_5pysam_14calignmentfile___iterdata iterdata;
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *samfile;
  struct __pyx_obj_5pysam_6cfaidx_Fastafile *fastafile;
  PyObject *stepper;
  int max_depth;
};


/* "pysam/calignmentfile.pxd":197
 *     cdef _free_pileup_iter(self)
 * 
 * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
 *     cdef int start
 *     cdef int end
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn __pyx_base;
  int start;
  int end;
  int truncate;
};


/* "pysam/calignmentfile.pxd":202
 *     cdef int truncate
 * 
 * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn __pyx_base;
};


/* "pysam/calignmentfile.pxd":205
 *     pass
 * 
 * cdef class IndexedReads:             # <<<<<<<<<<<<<<
 *     cdef AlignmentFile samfile
 *     cdef htsFile * htsfile
 */
struct __pyx_obj_5pysam_14calignmentfile_IndexedReads {
  PyObject_HEAD
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *samfile;
  htsFile *htsfile;
  PyObject *index;
  int owns_samfile;
  bam_hdr_t *header;
};


/* "pysam/calignmentfile.pyx":3832
 * 
 * 
 * cdef class SNPCall:             # <<<<<<<<<<<<<<
 *     '''the results of a SNP call.'''
 *     cdef int _tid
 */
struct __pyx_obj_5pysam_14calignmentfile_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/calignmentfile.pyx":112
 * cdef char* CODE2CIGAR= "MIDNSHP=X"
 * if IS_PYTHON3:
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
 */
struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr {
  PyObject_HEAD
  PyObject *__pyx_v_x;
  PyObject *__pyx_v_y;
  PyObject *__pyx_t_0;
  PyObject *__pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


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



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

struct __pyx_vtabstruct_5pysam_6cfaidx_FastaFile {
  char *(*_fetch)(struct __pyx_obj_5pysam_6cfaidx_FastaFile *, char *, int, int, int *);
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_FastaFile *__pyx_vtabptr_5pysam_6cfaidx_FastaFile;


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

struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile {
  kseq_t *(*getCurrent)(struct __pyx_obj_5pysam_6cfaidx_FastxFile *);
  int (*cnext)(struct __pyx_obj_5pysam_6cfaidx_FastxFile *);
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile *__pyx_vtabptr_5pysam_6cfaidx_FastxFile;


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

struct __pyx_vtabstruct_5pysam_6cfaidx_FastqFile {
  struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_FastqFile *__pyx_vtabptr_5pysam_6cfaidx_FastqFile;


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

struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile {
  struct __pyx_vtabstruct_5pysam_6cfaidx_FastaFile __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile *__pyx_vtabptr_5pysam_6cfaidx_Fastafile;


/* "cfaidx.pxd":41
 *     pass
 * 
 * cdef class Fastqfile(FastxFile):             # <<<<<<<<<<<<<<
 *     pass
 */

struct __pyx_vtabstruct_5pysam_6cfaidx_Fastqfile {
  struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_6cfaidx_Fastqfile *__pyx_vtabptr_5pysam_6cfaidx_Fastqfile;


/* "pysam/calignmentfile.pyx":2370
 * 
 * 
 * cdef class AlignedSegment:             # <<<<<<<<<<<<<<
 *     '''Class representing an aligned segment.
 * 
 */

struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignedSegment {
  PyObject *(*set_tag)(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_14calignmentfile_14AlignedSegment_set_tag *__pyx_optional_args);
  PyObject *(*get_tag)(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*has_tag)(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *, PyObject *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignedSegment *__pyx_vtabptr_5pysam_14calignmentfile_AlignedSegment;


/* "pysam/calignmentfile.pyx":238
 * 
 * 
 * cdef class AlignmentFile:             # <<<<<<<<<<<<<<
 *     '''*(filename, mode=None, template = None,
 *          reference_names=None, reference_lengths = None,
 */

struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignmentFile {
  bam_hdr_t *(*_buildHeader)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, PyObject *);
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *);
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *);
  int (*write)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *, int __pyx_skip_dispatch);
  char *(*_getrname)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, int);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignmentFile *__pyx_vtabptr_5pysam_14calignmentfile_AlignmentFile;


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

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *);
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion *__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowRegion;


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

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowHead {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *);
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowHead *__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowHead;


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

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowAll {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *);
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowAll *__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowAll;


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

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowSelection {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *);
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowSelection *__pyx_vtabptr_5pysam_14calignmentfile_IteratorRowSelection;


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

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn {
  int (*cnext)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *);
  char *(*getSequence)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *);
  PyObject *(*setMask)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *, PyObject *);
  PyObject *(*setupIteratorData)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData *__pyx_optional_args);
  PyObject *(*reset)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *, PyObject *, PyObject *, PyObject *);
  PyObject *(*_free_pileup_iter)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *);
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn *__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumn;


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

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnRegion {
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnRegion *__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnRegion;


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

struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnAllRefs {
  struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnAllRefs *__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnAllRefs;

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

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

static PyObject *__Pyx_GetBuiltinName(PyObject *name);

#ifndef CYTHON_PROFILE
  #define CYTHON_PROFILE 1
#endif
#ifndef CYTHON_TRACE
  #define CYTHON_TRACE 0
#endif
#if CYTHON_TRACE
  #undef CYTHON_PROFILE_REUSE_FRAME
#endif
#ifndef CYTHON_PROFILE_REUSE_FRAME
  #define CYTHON_PROFILE_REUSE_FRAME 0
#endif
#if CYTHON_PROFILE || CYTHON_TRACE
  #include "compile.h"
  #include "frameobject.h"
  #include "traceback.h"
  #if CYTHON_PROFILE_REUSE_FRAME
    #define CYTHON_FRAME_MODIFIER static
    #define CYTHON_FRAME_DEL
  #else
    #define CYTHON_FRAME_MODIFIER
    #define CYTHON_FRAME_DEL Py_CLEAR(__pyx_frame)
  #endif
  #define __Pyx_TraceDeclarations(codeobj)                            \
  static PyCodeObject *__pyx_frame_code = NULL;                      \
  CYTHON_FRAME_MODIFIER PyFrameObject *__pyx_frame = NULL;           \
  int __Pyx_use_tracing = 0;                                          \
  if (codeobj) __pyx_frame_code = (PyCodeObject*) codeobj;
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno)                            \
  {   PyThreadState* tstate = PyThreadState_GET();                                   \
      if (unlikely(tstate->use_tracing) && !tstate->tracing &&                       \
              (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {    \
          __Pyx_use_tracing = __Pyx_TraceSetupAndCall(&__pyx_frame_code, &__pyx_frame, funcname, srcfile, firstlineno);  \
      }                                                                              \
  }
  #define __Pyx_TraceException()                                                           \
  if (likely(!__Pyx_use_tracing)); else {                                                  \
      PyThreadState* tstate = PyThreadState_GET();                                         \
      if (tstate->use_tracing &&                                                           \
              (tstate->c_profilefunc || (CYTHON_TRACE && tstate->c_tracefunc))) {          \
          tstate->tracing++;                                                               \
          tstate->use_tracing = 0;                                                         \
          PyObject *exc_info = __Pyx_GetExceptionTuple();                                  \
          if (exc_info) {                                                                  \
              if (CYTHON_TRACE && tstate->c_tracefunc)                                     \
                  tstate->c_tracefunc(                                                     \
                      tstate->c_traceobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);      \
              tstate->c_profilefunc(                                                       \
                  tstate->c_profileobj, __pyx_frame, PyTrace_EXCEPTION, exc_info);        \
              Py_DECREF(exc_info);                                                         \
          }                                                                                \
          tstate->use_tracing = 1;                                                         \
          tstate->tracing--;                                                               \
      }                                                                                    \
  }
  #define __Pyx_TraceReturn(result)                                                       \
  if (likely(!__Pyx_use_tracing)); else {                                                 \
      PyThreadState* tstate = PyThreadState_GET();                                        \
      if (tstate->use_tracing) {                                                          \
          tstate->tracing++;                                                              \
          tstate->use_tracing = 0;                                                        \
          if (CYTHON_TRACE && tstate->c_tracefunc)                                        \
              tstate->c_tracefunc(                                                        \
                  tstate->c_traceobj, __pyx_frame, PyTrace_RETURN, (PyObject*)result);   \
          if (tstate->c_profilefunc)                                                      \
              tstate->c_profilefunc(                                                      \
                  tstate->c_profileobj, __pyx_frame, PyTrace_RETURN, (PyObject*)result); \
          CYTHON_FRAME_DEL;                                                               \
          tstate->use_tracing = 1;                                                        \
          tstate->tracing--;                                                              \
      }                                                                                   \
  }
  static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno);
  static int __Pyx_TraceSetupAndCall(PyCodeObject** code, PyFrameObject** frame, const char *funcname, const char *srcfile, int firstlineno);
#else
  #define __Pyx_TraceDeclarations(codeobj)
  #define __Pyx_TraceCall(funcname, srcfile, firstlineno)
  #define __Pyx_TraceException()
  #define __Pyx_TraceReturn(result)
#endif
#if CYTHON_TRACE
  #define __Pyx_TraceLine(lineno)                                                          \
  if (likely(!__Pyx_use_tracing)); else {                                                  \
      PyThreadState* tstate = PyThreadState_GET();                                         \
      if (unlikely(tstate->use_tracing && tstate->c_tracefunc)) {                          \
          __pyx_frame->f_lineno = lineno;                                                 \
          tstate->tracing++;                                                               \
          tstate->use_tracing = 0;                                                         \
          tstate->c_tracefunc(tstate->c_traceobj, __pyx_frame, PyTrace_LINE, NULL);       \
          tstate->use_tracing = 1;                                                         \
          tstate->tracing--;                                                               \
      }                                                                                    \
  }
#else
  #define __Pyx_TraceLine(lineno)
#endif

#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

#include <string.h>

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

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

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

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

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

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

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

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

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

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);

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

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

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

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

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

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

#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

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

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

static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);

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

#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

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

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);

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

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

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

static CYTHON_INLINE int __Pyx_IterFinish(void);

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

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

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

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

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

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

static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject* none = _PyList_Extend((PyListObject*)L, v);
    if (unlikely(!none))
        return -1;
    Py_DECREF(none);
    return 0;
#else
    return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v);
#endif
}

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

static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

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

static void* __Pyx_GetVtable(PyObject *dict);

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

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

#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;
        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;
    op->ob_size = 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;
    self->ob_size = 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->ob_size) {
        self->ob_size = n;
        return 0;
    }
    newsize = n + (n / 2) + 1;
    if (newsize <= self->allocated) {
        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;
    self->ob_size = n;
    self->allocated = newsize;
    return 0;
}
#endif

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

static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint8_t(uint8_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *);

static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value);

static CYTHON_INLINE uint16_t __Pyx_PyInt_As_uint16_t(PyObject *);

static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *);

static CYTHON_INLINE uint8_t __Pyx_PyInt_As_uint8_t(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value);

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);

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

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

static int __Pyx_check_binary_version(void);

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

static PyObject *__Pyx_ImportModule(const char *name);

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

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);

static char *__pyx_f_5pysam_14calignmentfile_13AlignmentFile__getrname(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, int __pyx_v_tid); /* proto*/
static int __pyx_f_5pysam_14calignmentfile_13AlignmentFile_write(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_read, int __pyx_skip_dispatch); /* proto*/
static bam_hdr_t *__pyx_f_5pysam_14calignmentfile_13AlignmentFile__buildHeader(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_new_header); /* proto*/
static bam1_t *__pyx_f_5pysam_14calignmentfile_13AlignmentFile_getCurrent(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_14calignmentfile_13AlignmentFile_cnext(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_14calignmentfile_17IteratorRowRegion_getCurrent(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_14calignmentfile_17IteratorRowRegion_cnext(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_14calignmentfile_15IteratorRowHead_getCurrent(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_14calignmentfile_15IteratorRowHead_cnext(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_14calignmentfile_14IteratorRowAll_getCurrent(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_14calignmentfile_14IteratorRowAll_cnext(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *__pyx_v_self); /* proto*/
static bam1_t *__pyx_f_5pysam_14calignmentfile_20IteratorRowSelection_getCurrent(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_14calignmentfile_20IteratorRowSelection_cnext(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *__pyx_v_self); /* proto*/
static int __pyx_f_5pysam_14calignmentfile_14IteratorColumn_cnext(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self); /* proto*/
static char *__pyx_f_5pysam_14calignmentfile_14IteratorColumn_getSequence(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_14IteratorColumn_setMask(CYTHON_UNUSED struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_mask); /* proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_14IteratorColumn_reset(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_end); /* proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_14IteratorColumn__free_pileup_iter(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_14AlignedSegment_set_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_14calignmentfile_14AlignedSegment_set_tag *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_14AlignedSegment_has_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch); /* proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_14AlignedSegment_get_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch); /* proto*/

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* Module declarations from 'cpython' */

/* Module declarations from '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 'cython' */

/* Module declarations from 'pysam.calignmentfile' */
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_AlignedSegment = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_AlignmentFile = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_PileupColumn = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_PileupRead = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRow = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowHead = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowAll = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorRowSelection = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorColumn = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorColumnRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IteratorColumnAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_IndexedReads = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile_SNPCall = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile___pyx_scope_struct__genexpr = 0;
static PyTypeObject *__pyx_ptype_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr = 0;
static PyObject *__pyx_v_5pysam_14calignmentfile__FILENAME_ENCODING = 0;
static char *__pyx_v_5pysam_14calignmentfile_CODE2CIGAR;
static int __pyx_v_5pysam_14calignmentfile_max_pos;
static PyObject *__pyx_f_5pysam_14calignmentfile_from_string_and_size(char *, size_t); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile__encodeFilename(PyObject *); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile__forceBytes(PyObject *); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile__charptr_to_str(char *); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile__forceStr(PyObject *); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_makeAlignedSegment(bam1_t *); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_makePileupColumn(bam_pileup1_t **, int, int, int); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_makePileupRead(bam_pileup1_t *); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_convertBinaryTagToList(uint8_t *); /*proto*/
static int __pyx_f_5pysam_14calignmentfile___advance_nofilter(void *, bam1_t *); /*proto*/
static int __pyx_f_5pysam_14calignmentfile___advance_all(void *, bam1_t *); /*proto*/
static int __pyx_f_5pysam_14calignmentfile___advance_snpcalls(void *, bam1_t *); /*proto*/
static CYTHON_INLINE int32_t __pyx_f_5pysam_14calignmentfile__getQueryStart(bam1_t *); /*proto*/
static CYTHON_INLINE int32_t __pyx_f_5pysam_14calignmentfile__getQueryEnd(bam1_t *); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_14calignmentfile__getSequenceRange(bam1_t *, uint32_t, uint32_t); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_14calignmentfile__getQualitiesRange(bam1_t *, uint32_t, uint32_t); /*proto*/
static CYTHON_INLINE uint8_t __pyx_f_5pysam_14calignmentfile__get_value_code(PyObject *, struct __pyx_opt_args_5pysam_14calignmentfile__get_value_code *__pyx_optional_args); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_14calignmentfile__get_value_type(PyObject *, struct __pyx_opt_args_5pysam_14calignmentfile__get_value_type *__pyx_optional_args); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_5pysam_14calignmentfile__pack_tags(PyObject *); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_set_verbosity(int, int __pyx_skip_dispatch); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_get_verbosity(int __pyx_skip_dispatch); /*proto*/
#define __Pyx_MODULE_NAME "pysam.calignmentfile"
int __pyx_module_is_main_pysam__calignmentfile = 0;

/* Implementation of 'pysam.calignmentfile' */
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_ord;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_IOError;
static PyObject *__pyx_builtin_OverflowError;
static PyObject *__pyx_builtin_NotImplementedError;
static PyObject *__pyx_builtin_OSError;
static PyObject *__pyx_builtin_AttributeError;
static PyObject *__pyx_builtin_zip;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_StopIteration;
static PyObject *__pyx_builtin_chr;
static PyObject *__pyx_builtin_min;
static PyObject *__pyx_builtin_max;
static PyObject *__pyx_builtin_map;
static PyObject *__pyx_builtin_NotImplemented;
static PyObject *__pyx_builtin_MemoryError;
static PyObject *__pyx_pf_5pysam_14calignmentfile_8genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_11genexpr(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_13AlignmentFile___cinit__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_2_isOpen(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_4_hasIndex(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6_open(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_14calignmentfile_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, PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_8gettid(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_10getrname(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_12_parseRegion(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_14reset(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_16seek(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, uint64_t __pyx_v_offset, int __pyx_v_where); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_18tell(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_20fetch(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_callback, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_22head(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_n, PyObject *__pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_24mate(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_read); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_26count(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_until_eof); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_28pileup(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_30count_coverage(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_chr, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_quality_threshold, PyObject *__pyx_v_read_callback); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_32close(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_34__dealloc__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_36write(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_read); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_38__enter__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_40__exit__(struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_13AlignmentFile_8filename___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_11nreferences___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_10references___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_7lengths___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6mapped___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_42_checkIndex(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_8unmapped___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_12nocoordinate___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_4text___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6header___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_44_buildLine(CYTHON_UNUSED struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_fields, PyObject *__pyx_v_record); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_46__iter__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_48__next__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6is_bam___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_7is_cram___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_9is_stream___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_9is_remote___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_11IteratorRow___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRow *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators); /* proto */
static void __pyx_pf_5pysam_14calignmentfile_11IteratorRow_2__dealloc__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRow *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_end, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_17IteratorRowRegion_2__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_17IteratorRowRegion_4__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_14calignmentfile_17IteratorRowRegion_6__dealloc__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_15IteratorRowHead___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_n, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_15IteratorRowHead_2__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_15IteratorRowHead_4__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14IteratorRowAll___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorRowAll_2__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorRowAll_4__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_18IteratorRowAllRefs___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_18IteratorRowAllRefs_2nextiter(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_18IteratorRowAllRefs_4__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_18IteratorRowAllRefs_6__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_20IteratorRowSelection___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_positions, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_20IteratorRowSelection_2__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_20IteratorRowSelection_4__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14IteratorColumn___cinit__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorColumn_2__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorColumn_7seq_len___get__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorColumn_4addReference(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_6cfaidx_Fastafile *__pyx_v_fastafile); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorColumn_6hasReference(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_14calignmentfile_14IteratorColumn_8__dealloc__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, int __pyx_v_truncate, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_20IteratorColumnRegion_2__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_21IteratorColumnAllRefs___cinit__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_21IteratorColumnAllRefs_2__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_toQualityString(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_qualities); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_2fromQualityString(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_quality_string); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment___init__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static void __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_2__dealloc__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4__str__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_6compare(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_other); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8__richcmp__(PyObject *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_other, int __pyx_v_op); /* proto */
static Py_hash_t __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10__hash__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10query_name___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10query_name_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qname); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4flag___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4flag_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_flag); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12reference_id___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12reference_id_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tid); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15reference_start___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15reference_start_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_pos); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15mapping_quality___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15mapping_quality_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigarstring___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigarstring_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_cigar); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mtid); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_20next_reference_start___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_20next_reference_start_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mpos); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12query_length___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15template_length___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15template_length_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_isize); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14query_sequence___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14query_sequence_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_seq); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15query_qualities___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15query_qualities_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3bin___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3bin_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_bin); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9is_paired___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9is_paired_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14is_proper_pair___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14is_proper_pair_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11is_unmapped___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11is_unmapped_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16mate_is_unmapped___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16mate_is_unmapped_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10is_reverse___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10is_reverse_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15mate_is_reverse___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15mate_is_reverse_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8is_read1___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8is_read1_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8is_read2___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8is_read2_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12is_secondary___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12is_secondary_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9is_qcfail___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9is_qcfail_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12is_duplicate___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12is_duplicate_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16is_supplementary___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16is_supplementary_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_13reference_end___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16reference_length___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_24query_alignment_sequence___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_25query_alignment_qualities___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_21query_alignment_start___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_19query_alignment_end___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_22query_alignment_length___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12get_reference_positions(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_full_length); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14infer_query_length(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_always); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16get_aligned_pairs(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_matches_only); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_18get_blocks(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_20get_overlap(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigartuples___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigartuples_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_values); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_22set_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_24has_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_26get_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_28get_tags(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_with_value_type); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_30set_tags(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5qname___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5qname_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3tid___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3tid_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3pos___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3pos_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mapq___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mapq_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rnext___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rnext_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5pnext___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5pnext_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5cigar___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5cigar_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4tlen___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4tlen_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3seq___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3seq_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qual___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qual_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4alen___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4alen_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4aend___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4aend_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4rlen___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4rlen_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5query___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5query_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5qqual___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5qqual_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_6qstart___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_6qstart_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qend___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qend_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qlen___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qlen_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mrnm___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mrnm_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mpos___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mpos_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rname___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rname_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5isize___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5isize_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_6blocks___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_13aligned_pairs___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15inferred_length___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9positions___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4tags___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4tags_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_32overlap(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_34opt(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_36setTag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_12PileupColumn___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_2__str__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_12reference_id___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_9nsegments___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_12PileupColumn_9nsegments_2__set__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self, PyObject *__pyx_v_n); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_13reference_pos___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_7pileups___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_3pos___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_12PileupColumn_3pos_2__set__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_3tid___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_12PileupColumn_3tid_2__set__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_1n___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_12PileupColumn_1n_2__set__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_10PileupRead___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_2__str__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_9alignment___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_14query_position___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_5indel___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_5level___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_6is_del___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_7is_head___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_7is_tail___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_10is_refskip___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_3tid___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_3pos___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_14reference_base___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_8genotype___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_17consensus_quality___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_11snp_quality___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_15mapping_quality___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_8coverage___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall___str__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self); /* proto */
static int __pyx_pf_5pysam_14calignmentfile_12IndexedReads___init__(struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_12IndexedReads_2build(struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_12IndexedReads_4find(struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *__pyx_v_self, PyObject *__pyx_v_query_name); /* proto */
static void __pyx_pf_5pysam_14calignmentfile_12IndexedReads_6__dealloc__(struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_4set_verbosity(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_verbosity); /* proto */
static PyObject *__pyx_pf_5pysam_14calignmentfile_6get_verbosity(CYTHON_UNUSED PyObject *__pyx_self); /* 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_14calignmentfile_AlignedSegment(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_AlignmentFile(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_PileupColumn(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_PileupRead(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRow(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRowRegion(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRowHead(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRowAll(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRowAllRefs(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRowSelection(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorColumn(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorColumnRegion(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorColumnAllRefs(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IndexedReads(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile_SNPCall(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile___pyx_scope_struct__genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static char __pyx_k_A[] = "A";
static char __pyx_k_B[] = "B";
static char __pyx_k_C[] = "C";
static char __pyx_k_D[] = "D";
static char __pyx_k_F[] = "F";
static char __pyx_k_H[] = "H";
static char __pyx_k_I[] = "I";
static char __pyx_k_L[] = "L";
static char __pyx_k_S[] = "S";
static char __pyx_k_Z[] = "Z";
static char __pyx_k_b[] = "b";
static char __pyx_k_c[] = "c";
static char __pyx_k_d[] = "d";
static char __pyx_k_f[] = "f";
static char __pyx_k_h[] = "h";
static char __pyx_k_i[] = "i";
static char __pyx_k_n[] = "n";
static char __pyx_k_r[] = "r";
static char __pyx_k_s[] = "@%s";
static char __pyx_k_w[] = "w";
static char __pyx_k_x[] = "x";
static char __pyx_k_AS[] = "AS";
static char __pyx_k_CL[] = "CL";
static char __pyx_k_CN[] = "CN";
static char __pyx_k_CO[] = "CO";
static char __pyx_k_DS[] = "DS";
static char __pyx_k_DT[] = "DT";
static char __pyx_k_FO[] = "FO";
static char __pyx_k_GO[] = "GO";
static char __pyx_k_HD[] = "HD";
static char __pyx_k_ID[] = "ID";
static char __pyx_k_KS[] = "KS";
static char __pyx_k_LB[] = "LB";
static char __pyx_k_LN[] = "LN";
static char __pyx_k_M5[] = "M5";
static char __pyx_k_PG[] = "PG";
static char __pyx_k_PI[] = "PI";
static char __pyx_k_PL[] = "PL";
static char __pyx_k_PN[] = "PN";
static char __pyx_k_PP[] = "PP";
static char __pyx_k_PU[] = "PU";
static char __pyx_k_RG[] = "RG";
static char __pyx_k_SM[] = "SM";
static char __pyx_k_SN[] = "SN";
static char __pyx_k_SO[] = "SO";
static char __pyx_k_SP[] = "SP";
static char __pyx_k_SQ[] = "SQ";
static char __pyx_k_UR[] = "UR";
static char __pyx_k_VN[] = "VN";
static char __pyx_k__4[] = "-";
static char __pyx_k__7[] = "";
static char __pyx_k_os[] = "os";
static char __pyx_k_rU[] = "rU";
static char __pyx_k_rb[] = "rb";
static char __pyx_k_rc[] = "rc";
static char __pyx_k_re[] = "re";
static char __pyx_k_wb[] = "wb";
static char __pyx_k_wc[] = "wc";
static char __pyx_k_wh[] = "wh";
static char __pyx_k__13[] = "[:-]";
static char __pyx_k__41[] = "\n";
static char __pyx_k__43[] = "@";
static char __pyx_k__46[] = "\t";
static char __pyx_k__50[] = ":";
static char __pyx_k__74[] = "<";
static char __pyx_k_all[] = "all";
static char __pyx_k_bai[] = ".bai";
static char __pyx_k_beg[] = "beg";
static char __pyx_k_c_2[] = "%c";
static char __pyx_k_chr[] = "chr";
static char __pyx_k_end[] = "end";
static char __pyx_k_ftp[] = "ftp:";
static char __pyx_k_get[] = "get";
static char __pyx_k_i_c[] = "%i%c";
static char __pyx_k_map[] = "map";
static char __pyx_k_max[] = "max";
static char __pyx_k_min[] = "min";
static char __pyx_k_ord[] = "ord";
static char __pyx_k_pos[] = "pos";
static char __pyx_k_raw[] = "raw";
static char __pyx_k_s_2[] = "s";
static char __pyx_k_s_s[] = "%s:%s";
static char __pyx_k_seq[] = "seq";
static char __pyx_k_sys[] = "sys";
static char __pyx_k_tag[] = "tag";
static char __pyx_k_tid[] = "tid";
static char __pyx_k_wb0[] = "wb0";
static char __pyx_k_wbu[] = "wbu";
static char __pyx_k_zip[] = "zip";
static char __pyx_k_Zidf[] = "Zidf";
static char __pyx_k_args[] = "args";
static char __pyx_k_crai[] = ".crai";
static char __pyx_k_flag[] = "flag";
static char __pyx_k_http[] = "http:";
static char __pyx_k_init[] = "__init__";
static char __pyx_k_join[] = "join";
static char __pyx_k_main[] = "__main__";
static char __pyx_k_mode[] = "mode";
static char __pyx_k_open[] = "_open";
static char __pyx_k_path[] = "path";
static char __pyx_k_port[] = "port";
static char __pyx_k_seek[] = "seek";
static char __pyx_k_send[] = "send";
static char __pyx_k_stop[] = "stop";
static char __pyx_k_tags[] = "tags";
static char __pyx_k_tell[] = "tell";
static char __pyx_k_test[] = "__test__";
static char __pyx_k_text[] = "text";
static char __pyx_k_warn[] = "warn";
static char __pyx_k_2sc_s[] = "2sc%s";
static char __pyx_k_all_2[] = "__all__";
static char __pyx_k_array[] = "array";
static char __pyx_k_ascii[] = "ascii";
static char __pyx_k_close[] = "close";
static char __pyx_k_fetch[] = "fetch";
static char __pyx_k_indel[] = "indel";
static char __pyx_k_items[] = "items";
static char __pyx_k_level[] = "level";
static char __pyx_k_split[] = "split";
static char __pyx_k_start[] = "start";
static char __pyx_k_strip[] = "strip";
static char __pyx_k_throw[] = "throw";
static char __pyx_k_types[] = "types";
static char __pyx_k_value[] = "value";
static char __pyx_k_where[] = "where";
static char __pyx_k_write[] = "write";
static char __pyx_k_2sc_is[] = "2sc%is";
static char __pyx_k_always[] = "always";
static char __pyx_k_append[] = "append";
static char __pyx_k_ctypes[] = "ctypes";
static char __pyx_k_decode[] = "decode";
static char __pyx_k_encode[] = "encode";
static char __pyx_k_exists[] = "exists";
static char __pyx_k_fields[] = "fields";
static char __pyx_k_gettid[] = "gettid";
static char __pyx_k_header[] = "header";
static char __pyx_k_import[] = "__import__";
static char __pyx_k_isOpen[] = "_isOpen";
static char __pyx_k_is_del[] = "is_del";
static char __pyx_k_offset[] = "offset";
static char __pyx_k_record[] = "record";
static char __pyx_k_region[] = "region";
static char __pyx_k_struct[] = "struct";
static char __pyx_k_IOError[] = "IOError";
static char __pyx_k_OSError[] = "OSError";
static char __pyx_k_compare[] = "compare";
static char __pyx_k_compile[] = "compile";
static char __pyx_k_findall[] = "findall";
static char __pyx_k_genexpr[] = "genexpr";
static char __pyx_k_get_tag[] = "get_tag";
static char __pyx_k_has_tag[] = "has_tag";
static char __pyx_k_is_head[] = "is_head";
static char __pyx_k_is_tail[] = "is_tail";
static char __pyx_k_islower[] = "islower";
static char __pyx_k_isupper[] = "isupper";
static char __pyx_k_lengths[] = "lengths";
static char __pyx_k_pileups[] = "pileups";
static char __pyx_k_replace[] = "replace";
static char __pyx_k_samfile[] = "samfile";
static char __pyx_k_set_tag[] = "set_tag";
static char __pyx_k_stepper[] = "stepper";
static char __pyx_k_KeyError[] = "KeyError";
static char __pyx_k_calcsize[] = "calcsize";
static char __pyx_k_callback[] = "callback";
static char __pyx_k_check_sq[] = "check_sq";
static char __pyx_k_coverage[] = "coverage";
static char __pyx_k_exc_type[] = "exc_type";
static char __pyx_k_filename[] = "filename";
static char __pyx_k_genotype[] = "genotype";
static char __pyx_k_get_tags[] = "get_tags";
static char __pyx_k_hasIndex[] = "_hasIndex";
static char __pyx_k_nextiter[] = "nextiter";
static char __pyx_k_nofilter[] = "nofilter";
static char __pyx_k_platform[] = "platform";
static char __pyx_k_samtools[] = "samtools";
static char __pyx_k_set_tags[] = "set_tags";
static char __pyx_k_tempfile[] = "tempfile";
static char __pyx_k_template[] = "template";
static char __pyx_k_truncate[] = "truncate";
static char __pyx_k_warnings[] = "warnings";
static char __pyx_k_2sccI_i_s[] = "2sccI%i%s";
static char __pyx_k_MIDNSHP_X[] = "MIDNSHP=X";
static char __pyx_k_TypeError[] = "TypeError";
static char __pyx_k_alignment[] = "alignment";
static char __pyx_k_buildLine[] = "_buildLine";
static char __pyx_k_enumerate[] = "enumerate";
static char __pyx_k_exc_value[] = "exc_value";
static char __pyx_k_fastafile[] = "fastafile";
static char __pyx_k_itertools[] = "itertools";
static char __pyx_k_max_depth[] = "max_depth";
static char __pyx_k_nsegments[] = "nsegments";
static char __pyx_k_pack_into[] = "pack_into";
static char __pyx_k_positions[] = "positions";
static char __pyx_k_qualities[] = "qualities";
static char __pyx_k_reference[] = "reference";
static char __pyx_k_traceback[] = "traceback";
static char __pyx_k_until_eof[] = "until_eof";
static char __pyx_k_CIGAR2CODE[] = "CIGAR2CODE";
static char __pyx_k_IS_PYTHON3[] = "IS_PYTHON3";
static char __pyx_k_PileupRead[] = "PileupRead";
static char __pyx_k_ValueError[] = "ValueError";
static char __pyx_k_checkIndex[] = "_checkIndex";
static char __pyx_k_get_blocks[] = "get_blocks";
static char __pyx_k_is_refskip[] = "is_refskip";
static char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static char __pyx_k_query_name[] = "query_name";
static char __pyx_k_references[] = "references";
static char __pyx_k_startswith[] = "startswith";
static char __pyx_k_value_type[] = "value_type";
static char __pyx_k_CIGAR_REGEX[] = "CIGAR_REGEX";
static char __pyx_k_IteratorRow[] = "IteratorRow";
static char __pyx_k_MemoryError[] = "MemoryError";
static char __pyx_k_add_sq_text[] = "add_sq_text";
static char __pyx_k_cigarstring[] = "cigarstring";
static char __pyx_k_cigartuples[] = "cigartuples";
static char __pyx_k_collections[] = "collections";
static char __pyx_k_d_MIDNSHP_X[] = "(\\d+)([MIDNSHP=X])";
static char __pyx_k_defaultdict[] = "defaultdict";
static char __pyx_k_full_length[] = "full_length";
static char __pyx_k_get_overlap[] = "get_overlap";
static char __pyx_k_nreferences[] = "nreferences";
static char __pyx_k_parseRegion[] = "_parseRegion";
static char __pyx_k_snp_quality[] = "snp_quality";
static char __pyx_k_IndexedReads[] = "IndexedReads";
static char __pyx_k_PileupColumn[] = "PileupColumn";
static char __pyx_k_SQ_SN_s_LN_s[] = "@SQ\tSN:%s\tLN:%s\n";
static char __pyx_k_check_header[] = "check_header";
static char __pyx_k_matches_only[] = "matches_only";
static char __pyx_k_query_length[] = "query_length";
static char __pyx_k_reference_id[] = "reference_id";
static char __pyx_k_AlignmentFile[] = "AlignmentFile";
static char __pyx_k_Invalid_tag_s[] = "Invalid tag: %s";
static char __pyx_k_OverflowError[] = "OverflowError";
static char __pyx_k_StopIteration[] = "StopIteration";
static char __pyx_k_VALID_HEADERS[] = "VALID_HEADERS";
static char __pyx_k_get_verbosity[] = "get_verbosity";
static char __pyx_k_read_callback[] = "read_callback";
static char __pyx_k_reference_end[] = "reference_end";
static char __pyx_k_reference_pos[] = "reference_pos";
static char __pyx_k_set_verbosity[] = "set_verbosity";
static char __pyx_k_AlignedSegment[] = "AlignedSegment";
static char __pyx_k_AttributeError[] = "AttributeError";
static char __pyx_k_IteratorColumn[] = "IteratorColumn";
static char __pyx_k_NotImplemented[] = "NotImplemented";
static char __pyx_k_mate_not_found[] = "mate not found";
static char __pyx_k_properties_bin[] = "properties bin";
static char __pyx_k_quality_string[] = "quality_string";
static char __pyx_k_query_position[] = "query_position";
static char __pyx_k_query_sequence[] = "query_sequence";
static char __pyx_k_reference_base[] = "reference_base";
static char __pyx_k_referencenames[] = "referencenames";
static char __pyx_k_truncated_file[] = "truncated file";
static char __pyx_k_unknown_type_s[] = "unknown type '%s'";
static char __pyx_k_mapping_quality[] = "mapping_quality";
static char __pyx_k_properties_flag[] = "properties flag";
static char __pyx_k_query_qualities[] = "query_qualities";
static char __pyx_k_reference_names[] = "reference_names";
static char __pyx_k_reference_start[] = "reference_start";
static char __pyx_k_template_length[] = "template_length";
static char __pyx_k_toQualityString[] = "toQualityString";
static char __pyx_k_with_value_type[] = "with_value_type";
static char __pyx_k_file_s_not_found[] = "file `%s` not found";
static char __pyx_k_read_s_not_found[] = "read %s not found";
static char __pyx_k_reference_length[] = "reference_length";
static char __pyx_k_referencelengths[] = "referencelengths";
static char __pyx_k_sam_write_failed[] = "sam write failed";
static char __pyx_k_consensus_quality[] = "consensus_quality";
static char __pyx_k_fromQualityString[] = "fromQualityString";
static char __pyx_k_get_aligned_pairs[] = "get_aligned_pairs";
static char __pyx_k_mapping_quality_2[] = "mapping quality";
static char __pyx_k_next_reference_id[] = "next_reference_id";
static char __pyx_k_quality_threshold[] = "quality_threshold";
static char __pyx_k_reference_lengths[] = "reference_lengths";
static char __pyx_k_tag_s_not_present[] = "tag '%s' not present";
static char __pyx_k_VALID_HEADER_ORDER[] = "VALID_HEADER_ORDER";
static char __pyx_k_VALID_HEADER_TYPES[] = "VALID_HEADER_TYPES";
static char __pyx_k_end_out_of_range_i[] = "end out of range (%i)";
static char __pyx_k_getdefaultencoding[] = "getdefaultencoding";
static char __pyx_k_infer_query_length[] = "infer_query_length";
static char __pyx_k_malformatted_tag_s[] = "malformatted tag: %s";
static char __pyx_k_mate_s_is_unmapped[] = "mate %s: is unmapped";
static char __pyx_k_multiple_iterators[] = "multiple_iterators";
static char __pyx_k_read_s_is_unpaired[] = "read %s: is unpaired";
static char __pyx_k_reference_filename[] = "reference_filename";
static char __pyx_k_true_if_QC_failure[] = "true if QC failure";
static char __pyx_k_NotImplementedError[] = "NotImplementedError";
static char __pyx_k_VALID_HEADER_FIELDS[] = "VALID_HEADER_FIELDS";
static char __pyx_k_invalid_reference_s[] = "invalid reference `%s`";
static char __pyx_k_query_alignment_end[] = "query_alignment_end";
static char __pyx_k_the_genotype_called[] = "the genotype called.";
static char __pyx_k_create_string_buffer[] = "create_string_buffer";
static char __pyx_k_invalid_value_type_s[] = "invalid value type '%s'";
static char __pyx_k_next_reference_start[] = "next_reference_start";
static char __pyx_k_pysam_calignmentfile[] = "pysam.calignmentfile";
static char __pyx_k_start_out_of_range_i[] = "start out of range (%i)";
static char __pyx_k_could_not_open_file_s[] = "could not open file `%s`";
static char __pyx_k_getfilesystemencoding[] = "getfilesystemencoding";
static char __pyx_k_header_line_without_s[] = "header line without '@': '%s'";
static char __pyx_k_query_alignment_start[] = "query_alignment_start";
static char __pyx_k_true_if_this_is_read1[] = "true if this is read1";
static char __pyx_k_true_if_this_is_read2[] = "true if this is read2";
static char __pyx_k_error_during_iteration[] = "error during iteration";
static char __pyx_k_query_alignment_length[] = "query_alignment_length";
static char __pyx_k_current_sequence_length[] = "current sequence length.";
static char __pyx_k_get_reference_positions[] = "get_reference_positions";
static char __pyx_k_query_alignment_sequence[] = "query_alignment_sequence";
static char __pyx_k_query_alignment_qualities[] = "query_alignment_qualities";
static char __pyx_k_unknown_auxilliary_type_s[] = "unknown auxilliary type '%s'";
static char __pyx_k_nucleotide_position_of_SNP[] = "nucleotide position of SNP.";
static char __pyx_k_tid_i_out_of_range_0_tid_i[] = "tid %i out of range 0<=tid<%i";
static char __pyx_k_0_based_leftmost_coordinate[] = "0-based leftmost coordinate";
static char __pyx_k_invalid_file_opening_mode_s[] = "invalid file opening mode `%s`";
static char __pyx_k_I_O_operation_on_closed_file[] = "I/O operation on closed file";
static char __pyx_k_callback_not_implemented_yet[] = "callback not implemented yet";
static char __pyx_k_no_index_available_for_fetch[] = "no index available for fetch";
static char __pyx_k_seek_no_available_in_streams[] = "seek no available in streams";
static char __pyx_k_true_if_the_mate_is_unmapped[] = "true if the mate is unmapped";
static char __pyx_k_no_index_available_for_pileup[] = "no index available for pileup";
static char __pyx_k_true_if_not_primary_alignment[] = "true if not primary alignment";
static char __pyx_k_Padding_BAM_CPAD_6_is_currently[] = "Padding (BAM_CPAD, 6) is currently not supported. Please implement. Sorry about that.";
static char __pyx_k_at_least_one_signed_integer_out[] = "at least one signed integer out of range of BAM/SAM specification";
static char __pyx_k_error_while_opening_index_for_s[] = "error while opening index for '%s'";
static char __pyx_k_fetch_called_on_bamfile_without[] = "fetch called on bamfile without index";
static char __pyx_k_file_does_not_have_valid_header[] = "file does not have valid header (mode='%s') - is it BAM format?";
static char __pyx_k_header_line_with_invalid_type_s[] = "header line with invalid type '%s': '%s'";
static char __pyx_k_ifs_devel_andreas_pysam_pysam_c[] = "/ifs/devel/andreas/pysam/pysam/calignmentfile.pyx";
static char __pyx_k_incomplete_sequence_information[] = "incomplete sequence information in '%s'";
static char __pyx_k_invalid_coordinates_start_i_end[] = "invalid coordinates: start (%i) > end (%i)";
static char __pyx_k_malformatted_header_no_in_field[] = "malformatted header: no ':' in field";
static char __pyx_k_number_of_reads_mapping_to_this[] = "number of reads mapping to this column.";
static char __pyx_k_quality_and_sequence_mismatch_i[] = "quality and sequence mismatch: %i != %i";
static char __pyx_k_term_reference_ID_note_This_fie[] = ":term:`reference` ID\n\n        .. note::\n\n            This field contains the index of the reference sequence in\n            the sequence dictionary. To obtain the name of the\n            reference sequence, use\n            :meth:`pysam.AlignmentFile.getrname()`\n\n        ";
static char __pyx_k_the_chromosome_ID_as_is_defined[] = "the chromosome ID as is defined in the header";
static char __pyx_k_the_query_template_name_None_if[] = "the query template name (None if not present)";
static char __pyx_k_the_root_mean_square_rms_of_the[] = "the root mean square (rms) of the mapping quality of all reads\n       involved in the call.";
static char __pyx_k_true_if_read_itself_is_unmapped[] = "true if read itself is unmapped";
static char __pyx_k_true_if_this_is_a_supplementary[] = "true if this is a supplementary alignment";
static char __pyx_k_unable_to_open_remote_index_for[] = "unable to open remote index for '%s'";
static char __pyx_k_1_iff_the_base_on_the_padded_rea[] = "1 iff the base on the padded read is a deletion";
static char __pyx_k_AlignmentFile_mapped_only_availa[] = "AlignmentFile.mapped only available in bam files";
static char __pyx_k_Argument_must_be_string_bytes_or[] = "Argument must be string, bytes or unicode.";
static char __pyx_k_Argument_must_be_string_or_unico[] = "Argument must be string or unicode.";
static char __pyx_k_Invalid_clipping_in_CIGAR_string[] = "Invalid clipping in CIGAR string";
static char __pyx_k_PileupColumn_accessed_after_iter[] = "PileupColumn accessed after iterator finished";
static char __pyx_k_Unsupported_value_type_in_set_op[] = "Unsupported value_type in set_option";
static char __pyx_k_a_class_pysam_AlignedSegment_obj[] = "a :class:`pysam.AlignedSegment` object of the aligned read";
static char __pyx_k_aligned_length_of_the_read_on_th[] = "aligned length of the read on the reference genome.\n\n        This is equal to `aend - pos`. Returns None if not available.";
static char __pyx_k_aligned_portion_of_the_read_This[] = "aligned portion of the read.\n\n        This is a substring of :attr:`seq` that excludes flanking\n        bases that were :term:`soft clipped` (None if not present). It\n        is equal to ``seq[qstart:qend]``.\n\n        SAM/BAM files may include extra flanking bases that are not\n        part of the alignment.  These bases may be the result of the\n        Smith-Waterman or other algorithms, which may not require\n        alignments that begin at the first residue or end at the last.\n        In addition, extra sequencing adapters, multiplex identifiers,\n        and low-quality bases that were not considered for alignment\n        may have been retained.\n\n        ";
static char __pyx_k_aligned_query_sequence_quality_v[] = "aligned query sequence quality values (None if not present). These\n        are the quality values that correspond to :attr:`query`, that\n        is, they exclude qualities of :term:`soft clipped` bases. This\n        is equal to ``qual[qstart:qend]``.\n\n        Quality scores are returned as a python array of unsigned\n        chars. Note that this is not the ASCII-encoded value typically\n        seen in FASTQ or SAM formatted files. Thus, no offset of 33\n        needs to be subtracted.\n\n        This property is read-only.\n\n        ";
static char __pyx_k_aligned_reference_position_of_th[] = "aligned reference position of the read on the reference genome.\n        \n        reference_end points to one past the last aligned residue.\n        Returns None if not available (read is unmapped or no cigar\n        alignment present).\n\n        ";
static char __pyx_k_at_least_one_integer_out_of_rang[] = "at least one integer out of range of BAM/SAM specification";
static char __pyx_k_can_not_iterate_over_samfile_wit[] = "can not iterate over samfile without header";
static char __pyx_k_can_only_IndexReads_on_bam_files[] = "can only IndexReads on bam files";
static char __pyx_k_can_t_guess_type_or_invalid_type[] = "can't guess type or invalid type code specified";
static char __pyx_k_could_not_open_file_mode_s_is_it[] = "could not open file (mode='%s') - is it SAM/BAM format?";
static char __pyx_k_coverage_or_read_depth_the_numbe[] = "coverage or read depth - the number of reads involved in the call.";
static char __pyx_k_either_supply_options_template_h[] = "either supply options `template`, `header` or  both `reference_names` and `reference_lengths` for writing";
static char __pyx_k_end_index_of_the_aligned_query_p[] = "end index of the aligned query portion of the sequence (0-based,\n        exclusive)";
static char __pyx_k_fetch_called_for_htsfile_without[] = "fetch called for htsfile without header";
static char __pyx_k_fetching_by_region_is_not_availa[] = "fetching by region is not available for sam files";
static char __pyx_k_file_header_is_empty_mode_s_is_i[] = "file header is empty (mode='%s') - is it SAM/BAM format?";
static char __pyx_k_filename_associated_with_this_ob[] = "filename associated with this object.";
static char __pyx_k_full_contents_of_the_term_sam_fi[] = "full contents of the :term:`sam file` header as a string\n    \n        See :attr:`pysam.AlignmentFile.header` to get a parsed\n        representation of the header.\n\n        ";
static char __pyx_k_header_information_within_the_te[] = "header information within the :term:`sam file`. The records and\n        fields are returned as a two-level dictionary. \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        ";
static char __pyx_k_indel_length_0_for_no_indel_posi[] = "indel length; 0 for no indel, positive for ins and negative            for del";
static char __pyx_k_invalid_type_for_record_s_s_expe[] = "invalid type for record %s: %s, expected %s";
static char __pyx_k_length_of_the_aligned_query_sequ[] = "length of the aligned query sequence.\n\n        This is equal to :attr:`qend` - :attr:`qstart`";
static char __pyx_k_list_of_reads_class_pysam_Pileup[] = "list of reads (:class:`pysam.PileupRead`) aligned to this column";
static char __pyx_k_mapping_information_not_recorded[] = "mapping information not recorded in index or index not available";
static char __pyx_k_multiple_s_lines_are_not_permitt[] = "multiple '%s' lines are not permitted";
static char __pyx_k_no_index_available_for_iteration[] = "no index available for iteration";
static char __pyx_k_number_of_term_reference_sequenc[] = "number of :term:`reference` sequences in the file.";
static char __pyx_k_pileup_of_samfiles_not_implement[] = "pileup of samfiles not implemented yet";
static char __pyx_k_position_of_the_read_base_at_the[] = "position of the read base at the pileup site, 0-based.\n        None if is_del or is_refskip is set.\n        \n        ";
static char __pyx_k_read_sequence_base_qualities_inc[] = "read sequence base qualities, including :term:`soft\n        clipped` bases (None if not present).\n\n        Quality scores are returned as a python array of unsigned\n        chars. Note that this is not the ASCII-encoded value typically\n        seen in FASTQ or SAM formatted files. Thus, no offset of 33\n        needs to be subtracted.\n\n        Note that to set quality scores the sequence has to be set\n        beforehand as this will determine the expected length of the\n        quality score array.\n\n        This method raises a ValueError if the length of the \n        quality scores and the sequence are not the same.\n\n        ";
static char __pyx_k_read_sequence_bases_including_te[] = "read sequence bases, including :term:`soft clipped` bases \n        (None if not present).\n\n        Note that assigning to seq will invalidate any quality scores.\n        Thus, to in-place edit the sequence and quality scores, copies of\n        the quality scores need to be taken. Consider trimming for example::\n\n           q = read.qual\n           read.seq = read.seq[5:10]\n           read.qual = q[5:10]\n\n        The sequence is returned as it is stored in the BAM file. Some mappers\n        might have stored a reverse complement of the original read \n        sequence.\n        ";
static char __pyx_k_reference_base_at_pos_N_if_no_re[] = "reference base at pos. ``N`` if no reference sequence supplied.";
static char __pyx_k_reference_id_i_out_of_range_0_ti[] = "reference_id %i out of range 0<=tid<%i";
static char __pyx_k_reference_sequence_for_s_tid_i_n[] = "reference sequence for '%s' (tid=%i) not found";
static char __pyx_k_seek_only_available_in_bam_files[] = "seek only available in bam files";
static char __pyx_k_start_index_of_the_aligned_query[] = "start index of the aligned query portion of the sequence (0-based,\n        inclusive).\n\n        This the index of the first base in :attr:`seq` that is not\n        soft-clipped.\n\n        ";
static char __pyx_k_the_genotype_quality_Phred_scale[] = "the genotype quality (Phred-scaled).";
static char __pyx_k_the_length_of_the_query_read_Thi[] = "the length of the query/read.\n\n        This value corresponds to the length of the sequence supplied\n        in the BAM/SAM file. The length of a query is 0 if there is no\n        sequence in the BAM/SAM file. In those cases, the read length\n        can be inferred from the CIGAR alignment, see\n        :meth:`pysam.AlignmentFile.infer_query_length.`.\n\n        The length includes soft-clipped bases and is equal to\n        ``len(query_sequence)``.\n\n        This property is read-only but can be set by providing a\n        sequence.\n\n        Returns 0 if not available.\n\n        ";
static char __pyx_k_the_level_of_the_read_in_the_vie[] = "the level of the read in the \"viewer\" mode";
static char __pyx_k_the_observed_query_template_leng[] = "the observed query template length";
static char __pyx_k_the_position_in_the_reference_se[] = "the position in the reference sequence (0-based).";
static char __pyx_k_the_position_of_the_mate_next_re[] = "the position of the mate/next read.";
static char __pyx_k_the_reference_sequence_number_as[] = "the reference sequence number as defined in the header";
static char __pyx_k_the_snp_quality_Phred_scaled_pro[] = "the snp quality (Phred scaled) - probability of consensus being\n       identical to reference sequence.";
static char __pyx_k_the_term_cigar_alignment_The_ali[] = "the :term:`cigar` alignment. The alignment\n        is returned as a list of tuples of (operation, length). \n\n        If the alignment is not present, None is returned.\n\n        The operations are:\n\n        +-----+--------------+-----+\n        |M    |BAM_CMATCH    |0    |\n        +-----+--------------+-----+\n        |I    |BAM_CINS      |1    |\n        +-----+--------------+-----+\n        |D    |BAM_CDEL      |2    |\n        +-----+--------------+-----+\n        |N    |BAM_CREF_SKIP |3    |\n        +-----+--------------+-----+\n        |S    |BAM_CSOFT_CLIP|4    |\n        +-----+--------------+-----+\n        |H    |BAM_CHARD_CLIP|5    |\n        +-----+--------------+-----+\n        |P    |BAM_CPAD      |6    |\n        +-----+--------------+-----+\n        |=    |BAM_CEQUAL    |7    |\n        +-----+--------------+-----+\n        |X    |BAM_CDIFF     |8    |\n        +-----+--------------+-----+\n\n        .. note::\n            The output is a list of (operation, length) tuples, such as\n            ``[(0, 30)]``.\n            This is different from the SAM specification and\n            the :attr:`cigarstring` property, which uses a\n            (length, operation) order, for example: ``30M``.\n\n        To unset the cigar property, assign an empty list\n        or None.\n        ";
static char __pyx_k_the_term_cigar_alignment_as_a_st[] = "the :term:`cigar` alignment as a string.\n        \n        The cigar string is a string of alternating integers\n        and characters denoting the length and the type of\n        an operation.\n\n        .. note::\n            The order length,operation is specified in the\n            SAM format. It is different from the order of\n            the :attr:`cigar` property.\n\n        Returns None if not present.\n\n        To unset the cigarstring, assign None or the\n        empty string.\n        ";
static char __pyx_k_the_term_reference_id_of_the_mat[] = "the :term:`reference` id of the mate/next read.";
static char __pyx_k_this_class_cannot_be_instantiate[] = "this class cannot be instantiated from Python";
static char __pyx_k_total_number_of_mapped_alignment[] = "total number of mapped alignments according\n        to the statistics recorded in the index.\n        ";
static char __pyx_k_total_number_of_reads_without_co[] = "total number of reads without coordinates according\n        to the statistics recorded in the index.\n        ";
static char __pyx_k_total_number_of_unmapped_reads_a[] = "total number of unmapped reads according\n        to the statistics recorded in the index.\n        ";
static char __pyx_k_true_if_optical_or_PCR_duplicate[] = "true if optical or PCR duplicate";
static char __pyx_k_true_if_read_is_mapped_in_a_prop[] = "true if read is mapped in a proper pair";
static char __pyx_k_true_if_read_is_mapped_to_revers[] = "true if read is mapped to reverse strand";
static char __pyx_k_true_if_read_is_paired_in_sequen[] = "true if read is paired in sequencing";
static char __pyx_k_true_is_read_is_mapped_to_revers[] = "true is read is mapped to reverse strand";
static char __pyx_k_tuple_of_the_lengths_of_the_term[] = "tuple of the lengths of the :term:`reference` sequences. The\n        lengths are in the same order as\n        :attr:`pysam.AlignmentFile.references`\n\n        ";
static char __pyx_k_tuple_with_the_names_of_term_ref[] = "tuple with the names of :term:`reference` sequences.";
static char __pyx_k_unequal_names_and_lengths_of_ref[] = "unequal names and lengths of reference sequences";
static char __pyx_k_unknown_field_code_s_in_record_s[] = "unknown field code '%s' in record '%s'";
static char __pyx_k_unknown_stepper_option_s_in_Iter[] = "unknown stepper option `%s` in IteratorColumn";
static char __pyx_k_file_does_not_have_valid_header_2[] = "file does not have valid header (mode='%s') - is it SAM format?";
static PyObject *__pyx_kp_s_2sc_is;
static PyObject *__pyx_kp_s_2sc_s;
static PyObject *__pyx_kp_s_2sccI_i_s;
static PyObject *__pyx_n_b_A;
static PyObject *__pyx_n_s_A;
static PyObject *__pyx_n_s_AS;
static PyObject *__pyx_n_s_AlignedSegment;
static PyObject *__pyx_n_s_AlignmentFile;
static PyObject *__pyx_kp_s_AlignmentFile_mapped_only_availa;
static PyObject *__pyx_kp_u_Argument_must_be_string_bytes_or;
static PyObject *__pyx_kp_u_Argument_must_be_string_or_unico;
static PyObject *__pyx_n_s_AttributeError;
static PyObject *__pyx_n_b_B;
static PyObject *__pyx_n_s_B;
static PyObject *__pyx_n_b_C;
static PyObject *__pyx_n_s_C;
static PyObject *__pyx_n_s_CIGAR2CODE;
static PyObject *__pyx_n_s_CIGAR_REGEX;
static PyObject *__pyx_n_s_CL;
static PyObject *__pyx_n_s_CN;
static PyObject *__pyx_n_s_CO;
static PyObject *__pyx_n_s_D;
static PyObject *__pyx_n_s_DS;
static PyObject *__pyx_n_s_DT;
static PyObject *__pyx_n_s_F;
static PyObject *__pyx_n_s_FO;
static PyObject *__pyx_n_s_GO;
static PyObject *__pyx_n_s_H;
static PyObject *__pyx_n_s_HD;
static PyObject *__pyx_n_b_I;
static PyObject *__pyx_n_s_I;
static PyObject *__pyx_n_s_ID;
static PyObject *__pyx_n_s_IOError;
static PyObject *__pyx_n_s_IS_PYTHON3;
static PyObject *__pyx_kp_s_I_O_operation_on_closed_file;
static PyObject *__pyx_n_s_IndexedReads;
static PyObject *__pyx_kp_s_Invalid_tag_s;
static PyObject *__pyx_n_s_IteratorColumn;
static PyObject *__pyx_n_s_IteratorRow;
static PyObject *__pyx_n_s_KS;
static PyObject *__pyx_n_s_KeyError;
static PyObject *__pyx_n_s_L;
static PyObject *__pyx_n_s_LB;
static PyObject *__pyx_n_s_LN;
static PyObject *__pyx_n_s_M5;
static PyObject *__pyx_n_s_MemoryError;
static PyObject *__pyx_n_s_NotImplemented;
static PyObject *__pyx_n_s_NotImplementedError;
static PyObject *__pyx_n_s_OSError;
static PyObject *__pyx_n_s_OverflowError;
static PyObject *__pyx_n_s_PG;
static PyObject *__pyx_n_s_PI;
static PyObject *__pyx_n_s_PL;
static PyObject *__pyx_n_s_PN;
static PyObject *__pyx_n_s_PP;
static PyObject *__pyx_n_s_PU;
static PyObject *__pyx_kp_s_Padding_BAM_CPAD_6_is_currently;
static PyObject *__pyx_n_s_PileupColumn;
static PyObject *__pyx_kp_s_PileupColumn_accessed_after_iter;
static PyObject *__pyx_n_s_PileupRead;
static PyObject *__pyx_n_s_RG;
static PyObject *__pyx_n_b_S;
static PyObject *__pyx_n_s_S;
static PyObject *__pyx_n_s_SM;
static PyObject *__pyx_n_s_SN;
static PyObject *__pyx_n_s_SO;
static PyObject *__pyx_n_s_SP;
static PyObject *__pyx_n_s_SQ;
static PyObject *__pyx_kp_s_SQ_SN_s_LN_s;
static PyObject *__pyx_n_s_StopIteration;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_n_s_UR;
static PyObject *__pyx_kp_s_Unsupported_value_type_in_set_op;
static PyObject *__pyx_n_s_VALID_HEADERS;
static PyObject *__pyx_n_s_VALID_HEADER_FIELDS;
static PyObject *__pyx_n_s_VALID_HEADER_ORDER;
static PyObject *__pyx_n_s_VALID_HEADER_TYPES;
static PyObject *__pyx_n_s_VN;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_n_b_Z;
static PyObject *__pyx_n_s_Z;
static PyObject *__pyx_n_s_Zidf;
static PyObject *__pyx_kp_s__13;
static PyObject *__pyx_kp_b__4;
static PyObject *__pyx_kp_s__41;
static PyObject *__pyx_kp_s__43;
static PyObject *__pyx_kp_s__46;
static PyObject *__pyx_kp_s__50;
static PyObject *__pyx_kp_s__7;
static PyObject *__pyx_kp_s__74;
static PyObject *__pyx_n_s_add_sq_text;
static PyObject *__pyx_n_s_alignment;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_s_all_2;
static PyObject *__pyx_n_s_always;
static PyObject *__pyx_n_s_append;
static PyObject *__pyx_n_s_args;
static PyObject *__pyx_n_s_array;
static PyObject *__pyx_n_s_ascii;
static PyObject *__pyx_kp_s_at_least_one_integer_out_of_rang;
static PyObject *__pyx_kp_s_at_least_one_signed_integer_out;
static PyObject *__pyx_n_s_b;
static PyObject *__pyx_kp_b_bai;
static PyObject *__pyx_n_s_beg;
static PyObject *__pyx_n_s_buildLine;
static PyObject *__pyx_n_b_c;
static PyObject *__pyx_n_s_c;
static PyObject *__pyx_kp_s_c_2;
static PyObject *__pyx_n_s_calcsize;
static PyObject *__pyx_n_s_callback;
static PyObject *__pyx_kp_s_callback_not_implemented_yet;
static PyObject *__pyx_kp_s_can_not_iterate_over_samfile_wit;
static PyObject *__pyx_kp_s_can_only_IndexReads_on_bam_files;
static PyObject *__pyx_kp_s_can_t_guess_type_or_invalid_type;
static PyObject *__pyx_n_s_checkIndex;
static PyObject *__pyx_n_s_check_header;
static PyObject *__pyx_n_s_check_sq;
static PyObject *__pyx_n_s_chr;
static PyObject *__pyx_n_s_cigarstring;
static PyObject *__pyx_n_s_cigartuples;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_collections;
static PyObject *__pyx_n_s_compare;
static PyObject *__pyx_n_s_compile;
static PyObject *__pyx_n_s_consensus_quality;
static PyObject *__pyx_kp_s_could_not_open_file_mode_s_is_it;
static PyObject *__pyx_kp_s_could_not_open_file_s;
static PyObject *__pyx_n_s_coverage;
static PyObject *__pyx_kp_b_crai;
static PyObject *__pyx_n_s_create_string_buffer;
static PyObject *__pyx_n_s_ctypes;
static PyObject *__pyx_n_s_d;
static PyObject *__pyx_kp_s_d_MIDNSHP_X;
static PyObject *__pyx_n_s_decode;
static PyObject *__pyx_n_s_defaultdict;
static PyObject *__pyx_kp_s_either_supply_options_template_h;
static PyObject *__pyx_n_s_encode;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_kp_s_end_out_of_range_i;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_kp_s_error_during_iteration;
static PyObject *__pyx_kp_s_error_while_opening_index_for_s;
static PyObject *__pyx_n_s_exc_type;
static PyObject *__pyx_n_s_exc_value;
static PyObject *__pyx_n_s_exists;
static PyObject *__pyx_n_b_f;
static PyObject *__pyx_n_s_f;
static PyObject *__pyx_n_s_fastafile;
static PyObject *__pyx_n_s_fetch;
static PyObject *__pyx_kp_s_fetch_called_for_htsfile_without;
static PyObject *__pyx_kp_s_fetch_called_on_bamfile_without;
static PyObject *__pyx_kp_s_fetching_by_region_is_not_availa;
static PyObject *__pyx_n_s_fields;
static PyObject *__pyx_kp_s_file_does_not_have_valid_header;
static PyObject *__pyx_kp_s_file_does_not_have_valid_header_2;
static PyObject *__pyx_kp_s_file_header_is_empty_mode_s_is_i;
static PyObject *__pyx_kp_s_file_s_not_found;
static PyObject *__pyx_n_s_filename;
static PyObject *__pyx_n_s_findall;
static PyObject *__pyx_n_s_flag;
static PyObject *__pyx_n_s_fromQualityString;
static PyObject *__pyx_kp_b_ftp;
static PyObject *__pyx_n_s_full_length;
static PyObject *__pyx_n_s_genexpr;
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_blocks;
static PyObject *__pyx_n_s_get_overlap;
static PyObject *__pyx_n_s_get_reference_positions;
static PyObject *__pyx_n_s_get_tag;
static PyObject *__pyx_n_s_get_tags;
static PyObject *__pyx_n_s_get_verbosity;
static PyObject *__pyx_n_s_getdefaultencoding;
static PyObject *__pyx_n_s_getfilesystemencoding;
static PyObject *__pyx_n_s_gettid;
static PyObject *__pyx_n_s_h;
static PyObject *__pyx_n_s_hasIndex;
static PyObject *__pyx_n_s_has_tag;
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_b_http;
static PyObject *__pyx_n_b_i;
static PyObject *__pyx_n_s_i;
static PyObject *__pyx_kp_s_i_c;
static PyObject *__pyx_kp_s_ifs_devel_andreas_pysam_pysam_c;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_kp_s_incomplete_sequence_information;
static PyObject *__pyx_n_s_indel;
static PyObject *__pyx_n_s_infer_query_length;
static PyObject *__pyx_n_s_init;
static PyObject *__pyx_kp_s_invalid_coordinates_start_i_end;
static PyObject *__pyx_kp_s_invalid_file_opening_mode_s;
static PyObject *__pyx_kp_s_invalid_reference_s;
static PyObject *__pyx_kp_s_invalid_type_for_record_s_s_expe;
static PyObject *__pyx_kp_s_invalid_value_type_s;
static PyObject *__pyx_n_s_isOpen;
static PyObject *__pyx_n_s_is_del;
static PyObject *__pyx_n_s_is_head;
static PyObject *__pyx_n_s_is_refskip;
static PyObject *__pyx_n_s_is_tail;
static PyObject *__pyx_n_s_islower;
static PyObject *__pyx_n_s_isupper;
static PyObject *__pyx_n_s_items;
static PyObject *__pyx_n_s_itertools;
static PyObject *__pyx_n_s_join;
static PyObject *__pyx_n_s_lengths;
static PyObject *__pyx_n_s_level;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_kp_s_malformatted_header_no_in_field;
static PyObject *__pyx_kp_s_malformatted_tag_s;
static PyObject *__pyx_n_s_map;
static PyObject *__pyx_kp_s_mapping_information_not_recorded;
static PyObject *__pyx_n_s_mapping_quality;
static PyObject *__pyx_n_s_matches_only;
static PyObject *__pyx_kp_s_mate_not_found;
static PyObject *__pyx_kp_s_mate_s_is_unmapped;
static PyObject *__pyx_n_s_max;
static PyObject *__pyx_n_s_max_depth;
static PyObject *__pyx_n_s_min;
static PyObject *__pyx_n_s_mode;
static PyObject *__pyx_n_s_multiple_iterators;
static PyObject *__pyx_kp_s_multiple_s_lines_are_not_permitt;
static PyObject *__pyx_n_s_n;
static PyObject *__pyx_n_s_next_reference_id;
static PyObject *__pyx_n_s_next_reference_start;
static PyObject *__pyx_n_s_nextiter;
static PyObject *__pyx_kp_s_no_index_available_for_fetch;
static PyObject *__pyx_kp_s_no_index_available_for_iteration;
static PyObject *__pyx_kp_s_no_index_available_for_pileup;
static PyObject *__pyx_n_s_nofilter;
static PyObject *__pyx_n_s_nreferences;
static PyObject *__pyx_n_s_nsegments;
static PyObject *__pyx_n_s_offset;
static PyObject *__pyx_n_s_open;
static PyObject *__pyx_n_s_ord;
static PyObject *__pyx_n_s_os;
static PyObject *__pyx_n_s_pack_into;
static PyObject *__pyx_n_s_parseRegion;
static PyObject *__pyx_n_s_path;
static PyObject *__pyx_kp_s_pileup_of_samfiles_not_implement;
static PyObject *__pyx_n_s_pileups;
static PyObject *__pyx_n_s_platform;
static PyObject *__pyx_n_s_port;
static PyObject *__pyx_n_s_pos;
static PyObject *__pyx_n_s_positions;
static PyObject *__pyx_n_s_pysam_calignmentfile;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_qualities;
static PyObject *__pyx_kp_s_quality_and_sequence_mismatch_i;
static PyObject *__pyx_n_s_quality_string;
static PyObject *__pyx_n_s_quality_threshold;
static PyObject *__pyx_n_s_query_alignment_end;
static PyObject *__pyx_n_s_query_alignment_length;
static PyObject *__pyx_n_s_query_alignment_qualities;
static PyObject *__pyx_n_s_query_alignment_sequence;
static PyObject *__pyx_n_s_query_alignment_start;
static PyObject *__pyx_n_s_query_length;
static PyObject *__pyx_n_s_query_name;
static PyObject *__pyx_n_s_query_position;
static PyObject *__pyx_n_s_query_qualities;
static PyObject *__pyx_n_s_query_sequence;
static PyObject *__pyx_n_s_r;
static PyObject *__pyx_n_s_rU;
static PyObject *__pyx_n_s_raw;
static PyObject *__pyx_n_s_rb;
static PyObject *__pyx_n_s_rc;
static PyObject *__pyx_n_s_re;
static PyObject *__pyx_n_s_read_callback;
static PyObject *__pyx_kp_s_read_s_is_unpaired;
static PyObject *__pyx_kp_s_read_s_not_found;
static PyObject *__pyx_n_s_record;
static PyObject *__pyx_n_s_reference;
static PyObject *__pyx_n_s_reference_base;
static PyObject *__pyx_n_s_reference_end;
static PyObject *__pyx_n_s_reference_filename;
static PyObject *__pyx_n_s_reference_id;
static PyObject *__pyx_kp_s_reference_id_i_out_of_range_0_ti;
static PyObject *__pyx_n_s_reference_length;
static PyObject *__pyx_n_s_reference_lengths;
static PyObject *__pyx_n_s_reference_names;
static PyObject *__pyx_n_s_reference_pos;
static PyObject *__pyx_kp_s_reference_sequence_for_s_tid_i_n;
static PyObject *__pyx_n_s_reference_start;
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_replace;
static PyObject *__pyx_kp_s_s;
static PyObject *__pyx_n_b_s_2;
static PyObject *__pyx_n_s_s_2;
static PyObject *__pyx_kp_s_s_s;
static PyObject *__pyx_kp_s_sam_write_failed;
static PyObject *__pyx_n_s_samfile;
static PyObject *__pyx_n_s_samtools;
static PyObject *__pyx_n_s_seek;
static PyObject *__pyx_kp_s_seek_no_available_in_streams;
static PyObject *__pyx_kp_s_seek_only_available_in_bam_files;
static PyObject *__pyx_n_s_send;
static PyObject *__pyx_n_s_seq;
static PyObject *__pyx_n_s_set_tag;
static PyObject *__pyx_n_s_set_tags;
static PyObject *__pyx_n_s_set_verbosity;
static PyObject *__pyx_n_s_snp_quality;
static PyObject *__pyx_n_s_split;
static PyObject *__pyx_n_s_start;
static PyObject *__pyx_kp_s_start_out_of_range_i;
static PyObject *__pyx_n_s_startswith;
static PyObject *__pyx_n_s_stepper;
static PyObject *__pyx_n_s_stop;
static PyObject *__pyx_n_s_strip;
static PyObject *__pyx_n_s_struct;
static PyObject *__pyx_n_s_sys;
static PyObject *__pyx_n_s_tag;
static PyObject *__pyx_kp_s_tag_s_not_present;
static PyObject *__pyx_n_s_tags;
static PyObject *__pyx_n_s_tell;
static PyObject *__pyx_n_s_tempfile;
static PyObject *__pyx_n_s_template;
static PyObject *__pyx_n_s_template_length;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_text;
static PyObject *__pyx_kp_s_this_class_cannot_be_instantiate;
static PyObject *__pyx_n_s_throw;
static PyObject *__pyx_n_s_tid;
static PyObject *__pyx_kp_s_tid_i_out_of_range_0_tid_i;
static PyObject *__pyx_n_s_toQualityString;
static PyObject *__pyx_n_s_traceback;
static PyObject *__pyx_n_s_truncate;
static PyObject *__pyx_kp_s_truncated_file;
static PyObject *__pyx_n_s_types;
static PyObject *__pyx_kp_s_unable_to_open_remote_index_for;
static PyObject *__pyx_kp_s_unequal_names_and_lengths_of_ref;
static PyObject *__pyx_kp_s_unknown_auxilliary_type_s;
static PyObject *__pyx_kp_s_unknown_field_code_s_in_record_s;
static PyObject *__pyx_kp_s_unknown_stepper_option_s_in_Iter;
static PyObject *__pyx_kp_s_unknown_type_s;
static PyObject *__pyx_n_s_until_eof;
static PyObject *__pyx_n_s_value;
static PyObject *__pyx_n_s_value_type;
static PyObject *__pyx_n_s_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_where;
static PyObject *__pyx_n_s_with_value_type;
static PyObject *__pyx_n_s_write;
static PyObject *__pyx_n_s_x;
static PyObject *__pyx_n_s_zip;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2;
static PyObject *__pyx_int_15;
static PyObject *__pyx_int_33;
static PyObject *__pyx_int_128;
static PyObject *__pyx_int_256;
static PyObject *__pyx_int_1796;
static PyObject *__pyx_int_8000;
static PyObject *__pyx_int_32768;
static PyObject *__pyx_int_65536;
static PyObject *__pyx_int_536870912;
static PyObject *__pyx_int_2147483648;
static PyObject *__pyx_int_4294967296;
static PyObject *__pyx_int_neg_4;
static PyObject *__pyx_int_neg_128;
static PyObject *__pyx_int_neg_32768;
static PyObject *__pyx_int_neg_2147483648;
static int __pyx_k__66;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_slice__8;
static PyObject *__pyx_slice__9;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_slice__45;
static PyObject *__pyx_slice__48;
static PyObject *__pyx_slice__49;
static PyObject *__pyx_slice__76;
static PyObject *__pyx_slice__77;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__12;
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__24;
static PyObject *__pyx_tuple__25;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_tuple__27;
static PyObject *__pyx_tuple__28;
static PyObject *__pyx_tuple__29;
static PyObject *__pyx_tuple__30;
static PyObject *__pyx_tuple__31;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__33;
static PyObject *__pyx_tuple__34;
static PyObject *__pyx_tuple__35;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__40;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__47;
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__61;
static PyObject *__pyx_tuple__62;
static PyObject *__pyx_tuple__63;
static PyObject *__pyx_tuple__64;
static PyObject *__pyx_tuple__65;
static PyObject *__pyx_tuple__67;
static PyObject *__pyx_tuple__68;
static PyObject *__pyx_tuple__71;
static PyObject *__pyx_tuple__72;
static PyObject *__pyx_tuple__73;
static PyObject *__pyx_tuple__75;
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_tuple__83;
static PyObject *__pyx_tuple__84;
static PyObject *__pyx_tuple__85;
static PyObject *__pyx_tuple__86;
static PyObject *__pyx_tuple__87;
static PyObject *__pyx_tuple__88;
static PyObject *__pyx_tuple__89;
static PyObject *__pyx_tuple__90;
static PyObject *__pyx_tuple__91;
static PyObject *__pyx_codeobj__69;
static PyObject *__pyx_codeobj__70;
static PyObject *__pyx_gb_5pysam_14calignmentfile_10generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_8genexpr(CYTHON_UNUSED PyObject *__pyx_self) {
  struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr *)__pyx_tp_new_5pysam_14calignmentfile___pyx_scope_struct__genexpr(__pyx_ptype_5pysam_14calignmentfile___pyx_scope_struct__genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __Pyx_TraceCall("genexpr", __pyx_f[0], 112);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_14calignmentfile_10generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

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

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

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

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_11genexpr(CYTHON_UNUSED PyObject *__pyx_self) {
  struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr *)__pyx_tp_new_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr(__pyx_ptype_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __Pyx_TraceCall("genexpr", __pyx_f[0], 114);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5pysam_14calignmentfile_13generator1, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  /* "pysam/calignmentfile.pyx":66
 *     ascii encoding.
 *     """
 *     if PY_MAJOR_VERSION < 3:             # <<<<<<<<<<<<<<
 *         return s
 *     elif s is None:
 */
  __pyx_t_1 = ((PY_MAJOR_VERSION < 3) != 0);
  if (__pyx_t_1) {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* "pysam/calignmentfile.pyx":127
 * #####################################################################
 * cdef class AlignedSegment
 * cdef object makeAlignedSegment(bam1_t * src):             # <<<<<<<<<<<<<<
 *     '''enter src into AlignedSegment.'''
 *     # note that the following does not call __init__
 */

static PyObject *__pyx_f_5pysam_14calignmentfile_makeAlignedSegment(bam1_t *__pyx_v_src) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_dest = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("makeAlignedSegment", 0);
  __Pyx_TraceCall("makeAlignedSegment", __pyx_f[0], 127);

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

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

  /* "pysam/calignmentfile.pyx":132
 *     cdef AlignedSegment dest = AlignedSegment.__new__(AlignedSegment)
 *     dest._delegate = bam_dup1(src)
 *     return dest             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_dest));
  __pyx_r = ((PyObject *)__pyx_v_dest);
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":127
 * #####################################################################
 * cdef class AlignedSegment
 * cdef object makeAlignedSegment(bam1_t * src):             # <<<<<<<<<<<<<<
 *     '''enter src into AlignedSegment.'''
 *     # note that the following does not call __init__
 */

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

/* "pysam/calignmentfile.pyx":136
 * 
 * cdef class PileupColumn
 * cdef makePileupColumn(bam_pileup1_t ** plp, int tid, int pos, int n_pu):             # <<<<<<<<<<<<<<
 *     # note that the following does not call __init__
 *      cdef PileupColumn dest = PileupColumn.__new__(PileupColumn)
 */

static PyObject *__pyx_f_5pysam_14calignmentfile_makePileupColumn(bam_pileup1_t **__pyx_v_plp, int __pyx_v_tid, int __pyx_v_pos, int __pyx_v_n_pu) {
  struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_dest = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("makePileupColumn", 0);
  __Pyx_TraceCall("makePileupColumn", __pyx_f[0], 136);

  /* "pysam/calignmentfile.pyx":138
 * cdef makePileupColumn(bam_pileup1_t ** plp, int tid, int pos, int n_pu):
 *     # note that the following does not call __init__
 *      cdef PileupColumn dest = PileupColumn.__new__(PileupColumn)             # <<<<<<<<<<<<<<
 *      dest.plp = plp
 *      dest.tid = tid
 */
  __pyx_t_1 = __pyx_tp_new_5pysam_14calignmentfile_PileupColumn(((PyTypeObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_PileupColumn)), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_14calignmentfile_PileupColumn)))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest = ((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_t_1);
  __pyx_t_1 = 0;

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

  /* "pysam/calignmentfile.pyx":140
 *      cdef PileupColumn dest = PileupColumn.__new__(PileupColumn)
 *      dest.plp = plp
 *      dest.tid = tid             # <<<<<<<<<<<<<<
 *      dest.pos = pos
 *      dest.n_pu = n_pu
 */
  __pyx_v_dest->tid = __pyx_v_tid;

  /* "pysam/calignmentfile.pyx":141
 *      dest.plp = plp
 *      dest.tid = tid
 *      dest.pos = pos             # <<<<<<<<<<<<<<
 *      dest.n_pu = n_pu
 *      return dest
 */
  __pyx_v_dest->pos = __pyx_v_pos;

  /* "pysam/calignmentfile.pyx":142
 *      dest.tid = tid
 *      dest.pos = pos
 *      dest.n_pu = n_pu             # <<<<<<<<<<<<<<
 *      return dest
 * 
 */
  __pyx_v_dest->n_pu = __pyx_v_n_pu;

  /* "pysam/calignmentfile.pyx":143
 *      dest.pos = pos
 *      dest.n_pu = n_pu
 *      return dest             # <<<<<<<<<<<<<<
 * 
 * cdef class PileupRead
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_dest));
  __pyx_r = ((PyObject *)__pyx_v_dest);
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":136
 * 
 * cdef class PileupColumn
 * cdef makePileupColumn(bam_pileup1_t ** plp, int tid, int pos, int n_pu):             # <<<<<<<<<<<<<<
 *     # note that the following does not call __init__
 *      cdef PileupColumn dest = PileupColumn.__new__(PileupColumn)
 */

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

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

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

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

  /* "pysam/calignmentfile.pyx":149
 *     '''fill a  PileupRead object from a bam_pileup1_t * object.'''
 *     cdef PileupRead dest = PileupRead.__new__(PileupRead)
 *     dest._alignment = makeAlignedSegment(src.b)             # <<<<<<<<<<<<<<
 *     dest._qpos = src.qpos
 *     dest._indel = src.indel
 */
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile_makeAlignedSegment(__pyx_v_src->b); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_14calignmentfile_AlignedSegment))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_dest->_alignment);
  __Pyx_DECREF(((PyObject *)__pyx_v_dest->_alignment));
  __pyx_v_dest->_alignment = ((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_t_1);
  __pyx_t_1 = 0;

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

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

  /* "pysam/calignmentfile.pyx":152
 *     dest._qpos = src.qpos
 *     dest._indel = src.indel
 *     dest._level = src.level             # <<<<<<<<<<<<<<
 *     dest._is_del = src.is_del
 *     dest._is_head = src.is_head
 */
  __pyx_t_3 = __pyx_v_src->level;
  __pyx_v_dest->_level = __pyx_t_3;

  /* "pysam/calignmentfile.pyx":153
 *     dest._indel = src.indel
 *     dest._level = src.level
 *     dest._is_del = src.is_del             # <<<<<<<<<<<<<<
 *     dest._is_head = src.is_head
 *     dest._is_tail = src.is_tail
 */
  __pyx_t_4 = __pyx_v_src->is_del;
  __pyx_v_dest->_is_del = __pyx_t_4;

  /* "pysam/calignmentfile.pyx":154
 *     dest._level = src.level
 *     dest._is_del = src.is_del
 *     dest._is_head = src.is_head             # <<<<<<<<<<<<<<
 *     dest._is_tail = src.is_tail
 *     dest._is_refskip = src.is_refskip
 */
  __pyx_t_4 = __pyx_v_src->is_head;
  __pyx_v_dest->_is_head = __pyx_t_4;

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

  /* "pysam/calignmentfile.pyx":156
 *     dest._is_head = src.is_head
 *     dest._is_tail = src.is_tail
 *     dest._is_refskip = src.is_refskip             # <<<<<<<<<<<<<<
 *     return dest
 * 
 */
  __pyx_t_4 = __pyx_v_src->is_refskip;
  __pyx_v_dest->_is_refskip = __pyx_t_4;

  /* "pysam/calignmentfile.pyx":157
 *     dest._is_tail = src.is_tail
 *     dest._is_refskip = src.is_refskip
 *     return dest             # <<<<<<<<<<<<<<
 * 
 * cdef convertBinaryTagToList( uint8_t * s ):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_dest));
  __pyx_r = ((PyObject *)__pyx_v_dest);
  goto __pyx_L0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  /* "pysam/calignmentfile.pyx":203
 *             s += 4
 * 
 *     return byte_size, nvalues, values             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint8_t(__pyx_v_byte_size); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_From_int32_t(__pyx_v_nvalues); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_values);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_values);
  __Pyx_GIVEREF(__pyx_v_values);
  __pyx_t_1 = 0;
  __pyx_t_4 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

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

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

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

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_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_14calignmentfile_13AlignmentFile___cinit__(((struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_13AlignmentFile___cinit__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 303);

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

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

  /* "pysam/calignmentfile.pyx":306
 *         self.htsfile = NULL
 *         self._filename = None
 *         self.is_bam = False             # <<<<<<<<<<<<<<
 *         self.is_stream = False
 *         self.is_cram = False
 */
  __pyx_v_self->is_bam = 0;

  /* "pysam/calignmentfile.pyx":307
 *         self._filename = None
 *         self.is_bam = False
 *         self.is_stream = False             # <<<<<<<<<<<<<<
 *         self.is_cram = False
 *         self.is_remote = False
 */
  __pyx_v_self->is_stream = 0;

  /* "pysam/calignmentfile.pyx":308
 *         self.is_bam = False
 *         self.is_stream = False
 *         self.is_cram = False             # <<<<<<<<<<<<<<
 *         self.is_remote = False
 * 
 */
  __pyx_v_self->is_cram = 0;

  /* "pysam/calignmentfile.pyx":309
 *         self.is_stream = False
 *         self.is_cram = False
 *         self.is_remote = False             # <<<<<<<<<<<<<<
 * 
 *         self._open(*args, **kwargs)
 */
  __pyx_v_self->is_remote = 0;

  /* "pysam/calignmentfile.pyx":311
 *         self.is_remote = False
 * 
 *         self._open(*args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 *         # allocate memory for iterator
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

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

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

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_2_isOpen[] = "AlignmentFile._isOpen(self)\nreturn true if htsfile has been opened.";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_3_isOpen(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_isOpen (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_2_isOpen(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

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

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

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

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

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

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_5_hasIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_4_hasIndex[] = "AlignmentFile._hasIndex(self)\nreturn true if htsfile has an existing (and opened) index.";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_5_hasIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_hasIndex (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_4_hasIndex(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

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

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

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

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

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

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_6_open[] = "AlignmentFile._open(self, filename, mode=None, AlignmentFile template=None, reference_names=None, reference_lengths=None, reference_filename=None, text=None, header=None, port=None, add_sq_text=True, check_header=True, check_sq=True, referencenames=None, referencelengths=None)\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        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_7_open(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_filename = 0;
  PyObject *__pyx_v_mode = 0;
  struct __pyx_obj_5pysam_14calignmentfile_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;
  PyObject *__pyx_v_port = 0;
  PyObject *__pyx_v_add_sq_text = 0;
  PyObject *__pyx_v_check_header = 0;
  PyObject *__pyx_v_check_sq = 0;
  PyObject *__pyx_v_referencenames = 0;
  PyObject *__pyx_v_referencelengths = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_open (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_filename,&__pyx_n_s_mode,&__pyx_n_s_template,&__pyx_n_s_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_check_header,&__pyx_n_s_check_sq,&__pyx_n_s_referencenames,&__pyx_n_s_referencelengths,0};
    PyObject* values[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};

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

    /* "pysam/calignmentfile.pyx":327
 *               filename,
 *               mode=None,
 *               AlignmentFile template=None,             # <<<<<<<<<<<<<<
 *               reference_names=None,
 *               reference_lengths=None,
 */
    values[2] = (PyObject *)((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)Py_None);

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

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

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

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

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

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

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

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

    /* "pysam/calignmentfile.pyx":336
 *               add_sq_text=True,
 *               check_header=True,
 *               check_sq=True,             # <<<<<<<<<<<<<<
 *               referencenames=None,
 *               referencelengths=None):
 */
    values[11] = ((PyObject *)Py_True);

    /* "pysam/calignmentfile.pyx":337
 *               check_header=True,
 *               check_sq=True,
 *               referencenames=None,             # <<<<<<<<<<<<<<
 *               referencelengths=None):
 *         '''open a sam, bam or cram formatted file.
 */
    values[12] = ((PyObject *)Py_None);

    /* "pysam/calignmentfile.pyx":338
 *               check_sq=True,
 *               referencenames=None,
 *               referencelengths=None):             # <<<<<<<<<<<<<<
 *         '''open a sam, bam or cram formatted file.
 * 
 */
    values[13] = ((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 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
        case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_filename)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mode);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_template);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reference_names);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reference_lengths);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reference_filename);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_text);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_header);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_port);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_add_sq_text);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_check_header);
          if (value) { values[10] = value; kw_args--; }
        }
        case 11:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_check_sq);
          if (value) { values[11] = value; kw_args--; }
        }
        case 12:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_referencenames);
          if (value) { values[12] = value; kw_args--; }
        }
        case 13:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_referencelengths);
          if (value) { values[13] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_open") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
        case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_filename = values[0];
    __pyx_v_mode = values[1];
    __pyx_v_template = ((struct __pyx_obj_5pysam_14calignmentfile_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_check_header = values[10];
    __pyx_v_check_sq = values[11];
    __pyx_v_referencenames = values[12];
    __pyx_v_referencelengths = values[13];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_open", 0, 1, 14, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 324; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.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_14calignmentfile_AlignmentFile, 1, "template", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6_open(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_filename, __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_check_header, __pyx_v_check_sq, __pyx_v_referencenames, __pyx_v_referencelengths);

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

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6_open(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_filename, PyObject *__pyx_v_mode, struct __pyx_obj_5pysam_14calignmentfile_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, PyObject *__pyx_v_port, PyObject *__pyx_v_add_sq_text, PyObject *__pyx_v_check_header, PyObject *__pyx_v_check_sq, PyObject *__pyx_v_referencenames, PyObject *__pyx_v_referencelengths) {
  CYTHON_UNUSED PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_v_bmode = 0;
  char *__pyx_v_ctext;
  PyObject *__pyx_v_n = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_name = NULL;
  PyObject *__pyx_v_fn = NULL;
  int __pyx_v_format_index;
  PyObject *__pyx_v_ref = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  Py_ssize_t __pyx_t_11;
  Py_ssize_t __pyx_t_12;
  PyObject *(*__pyx_t_13)(PyObject *);
  size_t __pyx_t_14;
  int32_t __pyx_t_15;
  long __pyx_t_16;
  uint32_t __pyx_t_17;
  char const *__pyx_t_18;
  int __pyx_t_19;
  int __pyx_t_20;
  char *__pyx_t_21;
  char const *__pyx_t_22;
  char const *__pyx_t_23;
  char const *__pyx_t_24;
  char const *__pyx_t_25;
  PyObject *__pyx_t_26 = NULL;
  char const *__pyx_t_27;
  int64_t __pyx_t_28;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_open", 0);
  __Pyx_TraceCall("_open", __pyx_f[0], 324);
  __Pyx_INCREF(__pyx_v_filename);
  __Pyx_INCREF(__pyx_v_mode);
  __Pyx_INCREF(__pyx_v_reference_names);
  __Pyx_INCREF(__pyx_v_reference_lengths);
  __Pyx_INCREF(__pyx_v_text);

  /* "pysam/calignmentfile.pyx":345
 *         '''
 *         # 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_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":346
 *         # 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);
    goto __pyx_L3;
  }
  __pyx_L3:;

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

    /* "pysam/calignmentfile.pyx":348
 *             reference_names = referencenames
 *         if referencelengths is not None:
 *             reference_lengths = referencelengths             # <<<<<<<<<<<<<<
 * 
 *         # read mode autodetection
 */
    __Pyx_INCREF(__pyx_v_referencelengths);
    __Pyx_DECREF_SET(__pyx_v_reference_lengths, __pyx_v_referencelengths);
    goto __pyx_L4;
  }
  __pyx_L4:;

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

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

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

        /* "pysam/calignmentfile.pyx":354
 *             try:
 *                 self._open(filename, 'rb',
 *                            template=template,             # <<<<<<<<<<<<<<
 *                            reference_names=reference_names,
 *                            reference_lengths=reference_lengths,
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_template, ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L6_error;}

        /* "pysam/calignmentfile.pyx":355
 *                 self._open(filename, 'rb',
 *                            template=template,
 *                            reference_names=reference_names,             # <<<<<<<<<<<<<<
 *                            reference_lengths=reference_lengths,
 *                            reference_filename=reference_filename,
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_reference_names, __pyx_v_reference_names) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L6_error;}

        /* "pysam/calignmentfile.pyx":356
 *                            template=template,
 *                            reference_names=reference_names,
 *                            reference_lengths=reference_lengths,             # <<<<<<<<<<<<<<
 *                            reference_filename=reference_filename,
 *                            text=text,
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_reference_lengths, __pyx_v_reference_lengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L6_error;}

        /* "pysam/calignmentfile.pyx":357
 *                            reference_names=reference_names,
 *                            reference_lengths=reference_lengths,
 *                            reference_filename=reference_filename,             # <<<<<<<<<<<<<<
 *                            text=text,
 *                            header=header,
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_reference_filename, __pyx_v_reference_filename) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L6_error;}

        /* "pysam/calignmentfile.pyx":358
 *                            reference_lengths=reference_lengths,
 *                            reference_filename=reference_filename,
 *                            text=text,             # <<<<<<<<<<<<<<
 *                            header=header,
 *                            port=port,
 */
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_text, __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 353; __pyx_clineno = __LINE__; goto __pyx_L6_error;}

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

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

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

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

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

        /* "pysam/calignmentfile.pyx":363
 *                            check_header=check_header,
 *                            check_sq=check_sq)
 *                 return             # <<<<<<<<<<<<<<
 *             except ValueError, msg:
 *                 pass
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L10_try_return;
      }
      __pyx_L6_error:;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;

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

    /* "pysam/calignmentfile.pyx":367
 *                 pass
 * 
 *             self._open(filename, 'r',             # <<<<<<<<<<<<<<
 *                        template=template,
 *                        reference_names=reference_names,
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_open); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_INCREF(__pyx_v_filename);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_filename);
    __Pyx_GIVEREF(__pyx_v_filename);
    __Pyx_INCREF(__pyx_n_s_r);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_n_s_r);
    __Pyx_GIVEREF(__pyx_n_s_r);
    __pyx_t_9 = PyDict_New(); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);

    /* "pysam/calignmentfile.pyx":368
 * 
 *             self._open(filename, 'r',
 *                        template=template,             # <<<<<<<<<<<<<<
 *                        reference_names=reference_names,
 *                        reference_lengths=reference_lengths,
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_template, ((PyObject *)__pyx_v_template)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignmentfile.pyx":369
 *             self._open(filename, 'r',
 *                        template=template,
 *                        reference_names=reference_names,             # <<<<<<<<<<<<<<
 *                        reference_lengths=reference_lengths,
 *                        reference_filename=reference_filename,
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_reference_names, __pyx_v_reference_names) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignmentfile.pyx":370
 *                        template=template,
 *                        reference_names=reference_names,
 *                        reference_lengths=reference_lengths,             # <<<<<<<<<<<<<<
 *                        reference_filename=reference_filename,
 *                        text=text,
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_reference_lengths, __pyx_v_reference_lengths) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignmentfile.pyx":371
 *                        reference_names=reference_names,
 *                        reference_lengths=reference_lengths,
 *                        reference_filename=reference_filename,             # <<<<<<<<<<<<<<
 *                        text=text,
 *                        header=header,
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_reference_filename, __pyx_v_reference_filename) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignmentfile.pyx":372
 *                        reference_lengths=reference_lengths,
 *                        reference_filename=reference_filename,
 *                        text=text,             # <<<<<<<<<<<<<<
 *                        header=header,
 *                        port=port,
 */
    if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_text, __pyx_v_text) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

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

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

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

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

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

  /* "pysam/calignmentfile.pyx":379
 *             return
 * 
 *         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_6 = __pyx_v_mode;
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L16_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_w, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L16_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_rb, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L16_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_wb, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L16_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_wh, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L16_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_wbu, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L16_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_rU, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L16_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_wb0, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L16_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_rc, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!__pyx_t_1) {
    } else {
      __pyx_t_2 = __pyx_t_1;
      goto __pyx_L16_bool_binop_done;
    }
    __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_wc, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_t_1;
    __pyx_L16_bool_binop_done:;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!(__pyx_t_2 != 0))) {

      /* "pysam/calignmentfile.pyx":382
 *                         "wbu", "rU", "wb0",
 *                         "rc", "wc"), \
 *             "invalid file opening mode `%s`" % mode             # <<<<<<<<<<<<<<
 * 
 *         # close a previously opened file
 */
      __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_invalid_file_opening_mode_s, __pyx_v_mode); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 382; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyErr_SetObject(PyExc_AssertionError, __pyx_t_6);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif

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

    /* "pysam/calignmentfile.pyx":386
 *         # close a previously opened file
 *         if self.htsfile != NULL:
 *             self.close()             # <<<<<<<<<<<<<<
 * 
 *         # for htslib, wbu seems to not work
 */
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    if (__pyx_t_8) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_9); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    goto __pyx_L26;
  }
  __pyx_L26:;

  /* "pysam/calignmentfile.pyx":389
 * 
 *         # for htslib, wbu seems to not work
 *         if mode == "wbu":             # <<<<<<<<<<<<<<
 *             mode = "wb0"
 * 
 */
  __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_mode, __pyx_n_s_wbu, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":390
 *         # for htslib, wbu seems to not work
 *         if mode == "wbu":
 *             mode = "wb0"             # <<<<<<<<<<<<<<
 * 
 *         cdef bytes bmode = mode.encode('ascii')
 */
    __Pyx_INCREF(__pyx_n_s_wb0);
    __Pyx_DECREF_SET(__pyx_v_mode, __pyx_n_s_wb0);
    goto __pyx_L27;
  }
  __pyx_L27:;

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

  /* "pysam/calignmentfile.pyx":393
 * 
 *         cdef bytes bmode = mode.encode('ascii')
 *         self._filename = filename = _encodeFilename(filename)             # <<<<<<<<<<<<<<
 * 
 *         # FIXME: Use htsFormat when it is available
 */
  __pyx_t_9 = __pyx_f_5pysam_14calignmentfile__encodeFilename(__pyx_v_filename); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_INCREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  __Pyx_GOTREF(__pyx_v_self->_filename);
  __Pyx_DECREF(__pyx_v_self->_filename);
  __pyx_v_self->_filename = __pyx_t_9;
  __Pyx_INCREF(__pyx_t_9);
  __Pyx_DECREF_SET(__pyx_v_filename, __pyx_t_9);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "pysam/calignmentfile.pyx":396
 * 
 *         # FIXME: Use htsFormat when it is available
 *         self.is_bam = len(mode) > 1 and mode[1] == 'b'             # <<<<<<<<<<<<<<
 *         self.is_cram = len(mode) > 1 and mode[1] == 'c'
 *         self.is_stream = filename == b"-"
 */
  __pyx_t_11 = PyObject_Length(__pyx_v_mode); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = ((__pyx_t_11 > 1) != 0);
  if (__pyx_t_1) {
  } else {
    __pyx_t_2 = __pyx_t_1;
    goto __pyx_L28_bool_binop_done;
  }
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_mode, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_9, __pyx_n_s_b, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_2 = __pyx_t_1;
  __pyx_L28_bool_binop_done:;
  __pyx_v_self->is_bam = __pyx_t_2;

  /* "pysam/calignmentfile.pyx":397
 *         # FIXME: Use htsFormat when it is available
 *         self.is_bam = len(mode) > 1 and mode[1] == 'b'
 *         self.is_cram = len(mode) > 1 and mode[1] == 'c'             # <<<<<<<<<<<<<<
 *         self.is_stream = filename == b"-"
 *         self.is_remote = filename.startswith(b"http:") or \
 */
  __pyx_t_11 = PyObject_Length(__pyx_v_mode); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = ((__pyx_t_11 > 1) != 0);
  if (__pyx_t_1) {
  } else {
    __pyx_t_2 = __pyx_t_1;
    goto __pyx_L30_bool_binop_done;
  }
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_mode, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_t_9, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_2 = __pyx_t_1;
  __pyx_L30_bool_binop_done:;
  __pyx_v_self->is_cram = __pyx_t_2;

  /* "pysam/calignmentfile.pyx":398
 *         self.is_bam = len(mode) > 1 and mode[1] == 'b'
 *         self.is_cram = len(mode) > 1 and mode[1] == 'c'
 *         self.is_stream = filename == b"-"             # <<<<<<<<<<<<<<
 *         self.is_remote = filename.startswith(b"http:") or \
 *                          filename.startswith(b"ftp:")
 */
  __pyx_t_9 = PyObject_RichCompare(__pyx_v_filename, __pyx_kp_b__4, Py_EQ); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_v_self->is_stream = __pyx_t_2;

  /* "pysam/calignmentfile.pyx":399
 *         self.is_cram = len(mode) > 1 and mode[1] == 'c'
 *         self.is_stream = filename == b"-"
 *         self.is_remote = filename.startswith(b"http:") or \             # <<<<<<<<<<<<<<
 *                          filename.startswith(b"ftp:")
 * 
 */
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_startswith); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!__pyx_t_1) {
  } else {
    __pyx_t_2 = __pyx_t_1;
    goto __pyx_L32_bool_binop_done;
  }

  /* "pysam/calignmentfile.pyx":400
 *         self.is_stream = filename == b"-"
 *         self.is_remote = filename.startswith(b"http:") or \
 *                          filename.startswith(b"ftp:")             # <<<<<<<<<<<<<<
 * 
 *         cdef char * ctext
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_filename, __pyx_n_s_startswith); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_t_2 = __pyx_t_1;
  __pyx_L32_bool_binop_done:;

  /* "pysam/calignmentfile.pyx":399
 *         self.is_cram = len(mode) > 1 and mode[1] == 'c'
 *         self.is_stream = filename == b"-"
 *         self.is_remote = filename.startswith(b"http:") or \             # <<<<<<<<<<<<<<
 *                          filename.startswith(b"ftp:")
 * 
 */
  __pyx_v_self->is_remote = __pyx_t_2;

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

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

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

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

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

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

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

      /* "pysam/calignmentfile.pyx":419
 *                      "or  both `reference_names` and `reference_lengths` "
 *                      "for writing")
 *                 assert len(reference_names) == len(reference_lengths), \             # <<<<<<<<<<<<<<
 *                     "unequal names and lengths of reference sequences"
 * 
 */
      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!Py_OptimizeFlag)) {
        __pyx_t_11 = PyObject_Length(__pyx_v_reference_names); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_12 = PyObject_Length(__pyx_v_reference_lengths); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (unlikely(!((__pyx_t_11 == __pyx_t_12) != 0))) {
          PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_unequal_names_and_lengths_of_ref);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
      }
      #endif

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

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

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

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

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

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

        /* "pysam/calignmentfile.pyx":427
 *                 self.header.n_targets = len(reference_names)
 *                 n = 0
 *                 for x in reference_names:             # <<<<<<<<<<<<<<
 *                     n += len(x) + 1
 *                 self.header.target_name = <char**>calloc(
 */
      }
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

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

      /* "pysam/calignmentfile.pyx":429
 *                 for x in reference_names:
 *                     n += len(x) + 1
 *                 self.header.target_name = <char**>calloc(             # <<<<<<<<<<<<<<
 *                     n, sizeof(char*))
 *                 self.header.target_len = <uint32_t*>calloc(
 */
      __pyx_v_self->header->target_name = ((char **)calloc(__pyx_t_14, (sizeof(char *))));

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

      /* "pysam/calignmentfile.pyx":431
 *                 self.header.target_name = <char**>calloc(
 *                     n, sizeof(char*))
 *                 self.header.target_len = <uint32_t*>calloc(             # <<<<<<<<<<<<<<
 *                     n, sizeof(uint32_t))
 *                 for x from 0 <= x < self.header.n_targets:
 */
      __pyx_v_self->header->target_len = ((uint32_t *)calloc(__pyx_t_14, (sizeof(uint32_t))));

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

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

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

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

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

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

      /* "pysam/calignmentfile.pyx":433
 *                 self.header.target_len = <uint32_t*>calloc(
 *                     n, sizeof(uint32_t))
 *                 for x from 0 <= x < self.header.n_targets:             # <<<<<<<<<<<<<<
 *                     self.header.target_len[x] = reference_lengths[x]
 *                     name = reference_names[x]
 */
      __pyx_t_9 = __Pyx_PyInt_From_long(__pyx_t_16); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 433; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_9);
      __pyx_t_9 = 0;

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

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

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

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

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

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

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

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

        /* "pysam/calignmentfile.pyx":448
 *                                     (_forceStr(reference_names[x]),
 *                                      reference_lengths[x]))
 *                     text = ''.join(text)             # <<<<<<<<<<<<<<
 * 
 *                 if text is not None:
 */
        __pyx_t_9 = __Pyx_PyString_Join(__pyx_kp_s__7, __pyx_v_text); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 448; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF_SET(__pyx_v_text, __pyx_t_9);
        __pyx_t_9 = 0;
        goto __pyx_L44;
      }
      __pyx_L44:;

      /* "pysam/calignmentfile.pyx":450
 *                     text = ''.join(text)
 * 
 *                 if text is not None:             # <<<<<<<<<<<<<<
 *                     # copy without \0
 *                     text = _forceBytes(text)
 */
      __pyx_t_2 = (__pyx_v_text != Py_None);
      __pyx_t_19 = (__pyx_t_2 != 0);
      if (__pyx_t_19) {

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

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

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

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

        /* "pysam/calignmentfile.pyx":457
 *                     self.header.text = <char*>calloc(
 *                         strlen(ctext), sizeof(char))
 *                     memcpy(self.header.text, ctext, strlen(ctext))             # <<<<<<<<<<<<<<
 * 
 *             # open file (hts_open is synonym with sam_open)
 */
        memcpy(__pyx_v_self->header->text, __pyx_v_ctext, strlen(__pyx_v_ctext));
        goto __pyx_L49;
      }
      __pyx_L49:;
    }
    __pyx_L35:;

    /* "pysam/calignmentfile.pyx":460
 * 
 *             # open file (hts_open is synonym with sam_open)
 *             self.htsfile = hts_open(filename, bmode)             # <<<<<<<<<<<<<<
 * 
 *             # set filename with reference sequences. If no filename
 */
    __pyx_t_22 = __Pyx_PyObject_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_22) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_23 = __Pyx_PyObject_AsString(__pyx_v_bmode); if (unlikely((!__pyx_t_23) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 460; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_self->htsfile = hts_open(__pyx_t_22, __pyx_t_23);

    /* "pysam/calignmentfile.pyx":465
 *             # is given, the CRAM reference arrays will be built from
 *             # the @SQ header in the header
 *             if self.is_cram and reference_filename:             # <<<<<<<<<<<<<<
 *                 # note that fn_aux takes ownership, so create
 *                 # a copy
 */
    __pyx_t_2 = (__pyx_v_self->is_cram != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_19 = __pyx_t_2;
      goto __pyx_L51_bool_binop_done;
    }
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reference_filename); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_19 = __pyx_t_2;
    __pyx_L51_bool_binop_done:;
    if (__pyx_t_19) {

      /* "pysam/calignmentfile.pyx":468
 *                 # note that fn_aux takes ownership, so create
 *                 # a copy
 *                 fn = _encodeFilename(reference_filename)             # <<<<<<<<<<<<<<
 *                 self.htsfile.fn_aux = strdup(fn)
 * 
 */
      __pyx_t_9 = __pyx_f_5pysam_14calignmentfile__encodeFilename(__pyx_v_reference_filename); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 468; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_v_fn = ((PyObject*)__pyx_t_9);
      __pyx_t_9 = 0;

      /* "pysam/calignmentfile.pyx":469
 *                 # a copy
 *                 fn = _encodeFilename(reference_filename)
 *                 self.htsfile.fn_aux = strdup(fn)             # <<<<<<<<<<<<<<
 * 
 *             # write header to htsfile
 */
      __pyx_t_24 = __Pyx_PyObject_AsString(__pyx_v_fn); if (unlikely((!__pyx_t_24) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_self->htsfile->fn_aux = strdup(__pyx_t_24);
      goto __pyx_L50;
    }
    __pyx_L50:;

    /* "pysam/calignmentfile.pyx":472
 * 
 *             # write header to htsfile
 *             if self.is_bam or self.is_cram or "h" in mode:             # <<<<<<<<<<<<<<
 *                 sam_hdr_write(self.htsfile, self.header)
 * 
 */
    __pyx_t_2 = (__pyx_v_self->is_bam != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_19 = __pyx_t_2;
      goto __pyx_L54_bool_binop_done;
    }
    __pyx_t_2 = (__pyx_v_self->is_cram != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_19 = __pyx_t_2;
      goto __pyx_L54_bool_binop_done;
    }
    __pyx_t_2 = (__Pyx_PySequence_Contains(__pyx_n_s_h, __pyx_v_mode, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 472; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = (__pyx_t_2 != 0);
    __pyx_t_19 = __pyx_t_1;
    __pyx_L54_bool_binop_done:;
    if (__pyx_t_19) {

      /* "pysam/calignmentfile.pyx":473
 *             # write header to htsfile
 *             if self.is_bam or self.is_cram or "h" in mode:
 *                 sam_hdr_write(self.htsfile, self.header)             # <<<<<<<<<<<<<<
 * 
 *         elif mode[0] == "r":
 */
      sam_hdr_write(__pyx_v_self->htsfile, __pyx_v_self->header);
      goto __pyx_L53;
    }
    __pyx_L53:;
    goto __pyx_L34;
  }

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

    /* "pysam/calignmentfile.pyx":477
 *         elif mode[0] == "r":
 *             # open file for reading
 *             if (filename != b"-"             # <<<<<<<<<<<<<<
 *                 and not self.is_remote
 *                 and not os.path.exists(filename)):
 */
    __pyx_t_1 = (__Pyx_PyBytes_Equals(__pyx_v_filename, __pyx_kp_b__4, Py_NE)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 477; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_1) {
    } else {
      __pyx_t_19 = __pyx_t_1;
      goto __pyx_L58_bool_binop_done;
    }

    /* "pysam/calignmentfile.pyx":478
 *             # open file for reading
 *             if (filename != b"-"
 *                 and not self.is_remote             # <<<<<<<<<<<<<<
 *                 and not os.path.exists(filename)):
 *                 raise IOError("file `%s` not found" % filename)
 */
    __pyx_t_1 = ((!(__pyx_v_self->is_remote != 0)) != 0);
    if (__pyx_t_1) {
    } else {
      __pyx_t_19 = __pyx_t_1;
      goto __pyx_L58_bool_binop_done;
    }

    /* "pysam/calignmentfile.pyx":479
 *             if (filename != b"-"
 *                 and not self.is_remote
 *                 and not os.path.exists(filename)):             # <<<<<<<<<<<<<<
 *                 raise IOError("file `%s` not found" % filename)
 * 
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_path); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_exists); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && 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);
      }
    }
    if (!__pyx_t_8) {
      __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_v_filename); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
    } else {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = NULL;
      __Pyx_INCREF(__pyx_v_filename);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_filename);
      __Pyx_GIVEREF(__pyx_v_filename);
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_7, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_2 = ((!__pyx_t_1) != 0);
    __pyx_t_19 = __pyx_t_2;
    __pyx_L58_bool_binop_done:;
    if (__pyx_t_19) {

      /* "pysam/calignmentfile.pyx":480
 *                 and not self.is_remote
 *                 and not os.path.exists(filename)):
 *                 raise IOError("file `%s` not found" % filename)             # <<<<<<<<<<<<<<
 * 
 *             # open file (hts_open is synonym with sam_open)
 */
      __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_file_s_not_found, __pyx_v_filename); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_9);
      __pyx_t_9 = 0;
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_9, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/calignmentfile.pyx":483
 * 
 *             # open file (hts_open is synonym with sam_open)
 *             self.htsfile = hts_open(filename, bmode)             # <<<<<<<<<<<<<<
 *             if self.htsfile == NULL:
 *                 raise ValueError(
 */
    __pyx_t_22 = __Pyx_PyObject_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_22) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_23 = __Pyx_PyObject_AsString(__pyx_v_bmode); if (unlikely((!__pyx_t_23) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_self->htsfile = hts_open(__pyx_t_22, __pyx_t_23);

    /* "pysam/calignmentfile.pyx":484
 *             # open file (hts_open is synonym with sam_open)
 *             self.htsfile = hts_open(filename, bmode)
 *             if self.htsfile == NULL:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "could not open file (mode='%s') - "
 */
    __pyx_t_19 = ((__pyx_v_self->htsfile == NULL) != 0);
    if (__pyx_t_19) {

      /* "pysam/calignmentfile.pyx":487
 *                 raise ValueError(
 *                     "could not open file (mode='%s') - "
 *                     "is it SAM/BAM format?" % mode)             # <<<<<<<<<<<<<<
 * 
 *             # bam files require a valid header
 */
      __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_could_not_open_file_mode_s_is_it, __pyx_v_mode); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);

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

    /* "pysam/calignmentfile.pyx":490
 * 
 *             # bam files require a valid header
 *             if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *                 self.header = sam_hdr_read(self.htsfile)
 *                 if self.header == NULL:
 */
    __pyx_t_2 = (__pyx_v_self->is_bam != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_19 = __pyx_t_2;
      goto __pyx_L63_bool_binop_done;
    }
    __pyx_t_2 = (__pyx_v_self->is_cram != 0);
    __pyx_t_19 = __pyx_t_2;
    __pyx_L63_bool_binop_done:;
    if (__pyx_t_19) {

      /* "pysam/calignmentfile.pyx":491
 *             # bam files require a valid header
 *             if self.is_bam or self.is_cram:
 *                 self.header = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *                 if self.header == NULL:
 *                     raise ValueError(
 */
      __pyx_v_self->header = sam_hdr_read(__pyx_v_self->htsfile);

      /* "pysam/calignmentfile.pyx":492
 *             if self.is_bam or self.is_cram:
 *                 self.header = sam_hdr_read(self.htsfile)
 *                 if self.header == NULL:             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "file does not have valid header (mode='%s') "
 */
      __pyx_t_19 = ((__pyx_v_self->header == NULL) != 0);
      if (__pyx_t_19) {

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

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

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

        /* "pysam/calignmentfile.pyx":500
 *                 # unmapped reads)
 *                 if check_header:
 *                     self.header = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *                     if self.header == NULL:
 *                         raise ValueError(
 */
        __pyx_v_self->header = sam_hdr_read(__pyx_v_self->htsfile);

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

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

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

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

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

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

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

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

  /* "pysam/calignmentfile.pyx":518
 * 
 *         # check for index and open if present
 *         cdef int format_index = -1             # <<<<<<<<<<<<<<
 *         if self.is_bam:
 *             format_index = HTS_FMT_BAI
 */
  __pyx_v_format_index = -1;

  /* "pysam/calignmentfile.pyx":519
 *         # check for index and open if present
 *         cdef int format_index = -1
 *         if self.is_bam:             # <<<<<<<<<<<<<<
 *             format_index = HTS_FMT_BAI
 *         elif self.is_cram:
 */
  __pyx_t_19 = (__pyx_v_self->is_bam != 0);
  if (__pyx_t_19) {

    /* "pysam/calignmentfile.pyx":520
 *         cdef int format_index = -1
 *         if self.is_bam:
 *             format_index = HTS_FMT_BAI             # <<<<<<<<<<<<<<
 *         elif self.is_cram:
 *             format_index = HTS_FMT_CRAI
 */
    __pyx_v_format_index = HTS_FMT_BAI;
    goto __pyx_L72;
  }

  /* "pysam/calignmentfile.pyx":521
 *         if self.is_bam:
 *             format_index = HTS_FMT_BAI
 *         elif self.is_cram:             # <<<<<<<<<<<<<<
 *             format_index = HTS_FMT_CRAI
 * 
 */
  __pyx_t_19 = (__pyx_v_self->is_cram != 0);
  if (__pyx_t_19) {

    /* "pysam/calignmentfile.pyx":522
 *             format_index = HTS_FMT_BAI
 *         elif self.is_cram:
 *             format_index = HTS_FMT_CRAI             # <<<<<<<<<<<<<<
 * 
 *         if mode[0] == "r" and (self.is_bam or self.is_cram):
 */
    __pyx_v_format_index = HTS_FMT_CRAI;
    goto __pyx_L72;
  }
  __pyx_L72:;

  /* "pysam/calignmentfile.pyx":524
 *             format_index = HTS_FMT_CRAI
 * 
 *         if mode[0] == "r" and (self.is_bam or self.is_cram):             # <<<<<<<<<<<<<<
 * 
 *             # open index for remote files
 */
  __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_mode, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_9, __pyx_n_s_r, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (__pyx_t_2) {
  } else {
    __pyx_t_19 = __pyx_t_2;
    goto __pyx_L74_bool_binop_done;
  }
  __pyx_t_2 = (__pyx_v_self->is_bam != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_19 = __pyx_t_2;
    goto __pyx_L74_bool_binop_done;
  }
  __pyx_t_2 = (__pyx_v_self->is_cram != 0);
  __pyx_t_19 = __pyx_t_2;
  __pyx_L74_bool_binop_done:;
  if (__pyx_t_19) {

    /* "pysam/calignmentfile.pyx":527
 * 
 *             # open index for remote files
 *             if self.is_remote:             # <<<<<<<<<<<<<<
 *                 self.index = hts_idx_load(filename, format_index)
 *                 if self.index == NULL:
 */
    __pyx_t_19 = (__pyx_v_self->is_remote != 0);
    if (__pyx_t_19) {

      /* "pysam/calignmentfile.pyx":528
 *             # open index for remote files
 *             if self.is_remote:
 *                 self.index = hts_idx_load(filename, format_index)             # <<<<<<<<<<<<<<
 *                 if self.index == NULL:
 *                     warnings.warn(
 */
      __pyx_t_25 = __Pyx_PyObject_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_25) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_self->index = hts_idx_load(__pyx_t_25, __pyx_v_format_index);

      /* "pysam/calignmentfile.pyx":529
 *             if self.is_remote:
 *                 self.index = hts_idx_load(filename, format_index)
 *                 if self.index == NULL:             # <<<<<<<<<<<<<<
 *                     warnings.warn(
 *                         "unable to open remote index for '%s'" % filename)
 */
      __pyx_t_19 = ((__pyx_v_self->index == NULL) != 0);
      if (__pyx_t_19) {

        /* "pysam/calignmentfile.pyx":530
 *                 self.index = hts_idx_load(filename, format_index)
 *                 if self.index == NULL:
 *                     warnings.warn(             # <<<<<<<<<<<<<<
 *                         "unable to open remote index for '%s'" % filename)
 *             else:
 */
        __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_warn); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "pysam/calignmentfile.pyx":531
 *                 if self.index == NULL:
 *                     warnings.warn(
 *                         "unable to open remote index for '%s'" % filename)             # <<<<<<<<<<<<<<
 *             else:
 *                 if self.is_bam \
 */
        __pyx_t_6 = __Pyx_PyString_Format(__pyx_kp_s_unable_to_open_remote_index_for, __pyx_v_filename); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_8 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
          }
        }
        if (!__pyx_t_8) {
          __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_9);
        } else {
          __pyx_t_26 = PyTuple_New(1+1); if (unlikely(!__pyx_t_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_26);
          PyTuple_SET_ITEM(__pyx_t_26, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = NULL;
          PyTuple_SET_ITEM(__pyx_t_26, 0+1, __pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_26, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        goto __pyx_L78;
      }
      __pyx_L78:;
      goto __pyx_L77;
    }
    /*else*/ {

      /* "pysam/calignmentfile.pyx":533
 *                         "unable to open remote index for '%s'" % filename)
 *             else:
 *                 if self.is_bam \             # <<<<<<<<<<<<<<
 *                    and not os.path.exists(filename + b".bai") \
 *                    and not os.path.exists(filename[:-4] + b".bai"):
 */
      __pyx_t_2 = (__pyx_v_self->is_bam != 0);
      if (__pyx_t_2) {
      } else {
        __pyx_t_19 = __pyx_t_2;
        goto __pyx_L80_bool_binop_done;
      }

      /* "pysam/calignmentfile.pyx":534
 *             else:
 *                 if self.is_bam \
 *                    and not os.path.exists(filename + b".bai") \             # <<<<<<<<<<<<<<
 *                    and not os.path.exists(filename[:-4] + b".bai"):
 *                     self.index = NULL
 */
      __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_26 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_path); if (unlikely(!__pyx_t_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_26);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_26, __pyx_n_s_exists); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
      __pyx_t_26 = PyNumber_Add(__pyx_v_filename, __pyx_kp_b_bai); if (unlikely(!__pyx_t_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_26);
      __pyx_t_6 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && 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);
        }
      }
      if (!__pyx_t_6) {
        __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_26); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
        __Pyx_GOTREF(__pyx_t_9);
      } else {
        __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = NULL;
        PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_26);
        __Pyx_GIVEREF(__pyx_t_26);
        __pyx_t_26 = 0;
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_1 = ((!__pyx_t_2) != 0);
      if (__pyx_t_1) {
      } else {
        __pyx_t_19 = __pyx_t_1;
        goto __pyx_L80_bool_binop_done;
      }

      /* "pysam/calignmentfile.pyx":535
 *                 if self.is_bam \
 *                    and not os.path.exists(filename + b".bai") \
 *                    and not os.path.exists(filename[:-4] + b".bai"):             # <<<<<<<<<<<<<<
 *                     self.index = NULL
 *                 elif self.is_cram \
 */
      __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_path); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_exists); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetSlice(__pyx_v_filename, 0, -4, NULL, NULL, &__pyx_slice__8, 0, 1, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_26 = PyNumber_Add(__pyx_t_8, __pyx_kp_b_bai); if (unlikely(!__pyx_t_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_26);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      if (!__pyx_t_8) {
        __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_26); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
        __Pyx_GOTREF(__pyx_t_9);
      } else {
        __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = NULL;
        PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_26);
        __Pyx_GIVEREF(__pyx_t_26);
        __pyx_t_26 = 0;
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_6, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_2 = ((!__pyx_t_1) != 0);
      __pyx_t_19 = __pyx_t_2;
      __pyx_L80_bool_binop_done:;
      if (__pyx_t_19) {

        /* "pysam/calignmentfile.pyx":536
 *                    and not os.path.exists(filename + b".bai") \
 *                    and not os.path.exists(filename[:-4] + b".bai"):
 *                     self.index = NULL             # <<<<<<<<<<<<<<
 *                 elif self.is_cram \
 *                      and not os.path.exists(filename + b".crai") \
 */
        __pyx_v_self->index = NULL;
        goto __pyx_L79;
      }

      /* "pysam/calignmentfile.pyx":537
 *                    and not os.path.exists(filename[:-4] + b".bai"):
 *                     self.index = NULL
 *                 elif self.is_cram \             # <<<<<<<<<<<<<<
 *                      and not os.path.exists(filename + b".crai") \
 *                      and not os.path.exists(filename[:-4] + b".crai"):
 */
      __pyx_t_2 = (__pyx_v_self->is_cram != 0);
      if (__pyx_t_2) {
      } else {
        __pyx_t_19 = __pyx_t_2;
        goto __pyx_L83_bool_binop_done;
      }

      /* "pysam/calignmentfile.pyx":538
 *                     self.index = NULL
 *                 elif self.is_cram \
 *                      and not os.path.exists(filename + b".crai") \             # <<<<<<<<<<<<<<
 *                      and not os.path.exists(filename[:-4] + b".crai"):
 *                     self.index = NULL
 */
      __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_path); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_exists); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyNumber_Add(__pyx_v_filename, __pyx_kp_b_crai); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_26 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_26 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_26)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_26);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      if (!__pyx_t_26) {
        __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_9);
      } else {
        __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_26); __Pyx_GIVEREF(__pyx_t_26); __pyx_t_26 = NULL;
        PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_1 = ((!__pyx_t_2) != 0);
      if (__pyx_t_1) {
      } else {
        __pyx_t_19 = __pyx_t_1;
        goto __pyx_L83_bool_binop_done;
      }

      /* "pysam/calignmentfile.pyx":539
 *                 elif self.is_cram \
 *                      and not os.path.exists(filename + b".crai") \
 *                      and not os.path.exists(filename[:-4] + b".crai"):             # <<<<<<<<<<<<<<
 *                     self.index = NULL
 *                 else:
 */
      __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_path); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_exists); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetSlice(__pyx_v_filename, 0, -4, NULL, NULL, &__pyx_slice__9, 0, 1, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_6 = PyNumber_Add(__pyx_t_8, __pyx_kp_b_crai); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      if (!__pyx_t_8) {
        __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_9);
      } else {
        __pyx_t_26 = PyTuple_New(1+1); if (unlikely(!__pyx_t_26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_26);
        PyTuple_SET_ITEM(__pyx_t_26, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = NULL;
        PyTuple_SET_ITEM(__pyx_t_26, 0+1, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_26, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_2 = ((!__pyx_t_1) != 0);
      __pyx_t_19 = __pyx_t_2;
      __pyx_L83_bool_binop_done:;
      if (__pyx_t_19) {

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

        /* "pysam/calignmentfile.pyx":545
 *                     # not be opened
 *                     self.index = sam_index_load(self.htsfile,
 *                                                 filename)             # <<<<<<<<<<<<<<
 *                     if self.index == NULL:
 *                         raise IOError(
 */
        __pyx_t_27 = __Pyx_PyObject_AsString(__pyx_v_filename); if (unlikely((!__pyx_t_27) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 545; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "pysam/calignmentfile.pyx":544
 *                     # returns NULL if there is no index or index could
 *                     # not be opened
 *                     self.index = sam_index_load(self.htsfile,             # <<<<<<<<<<<<<<
 *                                                 filename)
 *                     if self.index == NULL:
 */
        __pyx_v_self->index = sam_index_load(__pyx_v_self->htsfile, __pyx_t_27);

        /* "pysam/calignmentfile.pyx":546
 *                     self.index = sam_index_load(self.htsfile,
 *                                                 filename)
 *                     if self.index == NULL:             # <<<<<<<<<<<<<<
 *                         raise IOError(
 *                             "error while opening index for '%s'" %
 */
        __pyx_t_19 = ((__pyx_v_self->index == NULL) != 0);
        if (__pyx_t_19) {

          /* "pysam/calignmentfile.pyx":548
 *                     if self.index == NULL:
 *                         raise IOError(
 *                             "error while opening index for '%s'" %             # <<<<<<<<<<<<<<
 *                             filename)
 * 
 */
          __pyx_t_9 = __Pyx_PyString_Format(__pyx_kp_s_error_while_opening_index_for_s, __pyx_v_filename); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 548; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_9);

          /* "pysam/calignmentfile.pyx":547
 *                                                 filename)
 *                     if self.index == NULL:
 *                         raise IOError(             # <<<<<<<<<<<<<<
 *                             "error while opening index for '%s'" %
 *                             filename)
 */
          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 547; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_9);
          __pyx_t_9 = 0;
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 547; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_Raise(__pyx_t_9, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 547; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
      }
      __pyx_L79:;
    }
    __pyx_L77:;

    /* "pysam/calignmentfile.pyx":552
 * 
 *             # save start of data section
 *             if not self.is_stream:             # <<<<<<<<<<<<<<
 *                 self.start_offset = self.tell()
 * 
 */
    __pyx_t_19 = ((!(__pyx_v_self->is_stream != 0)) != 0);
    if (__pyx_t_19) {

      /* "pysam/calignmentfile.pyx":553
 *             # save start of data section
 *             if not self.is_stream:
 *                 self.start_offset = self.tell()             # <<<<<<<<<<<<<<
 * 
 *     def gettid(self, reference):
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tell); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_26 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_26 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_26)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_26);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
        }
      }
      if (__pyx_t_26) {
        __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_26); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
      } else {
        __pyx_t_9 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_28 = __Pyx_PyInt_As_int64_t(__pyx_t_9); if (unlikely((__pyx_t_28 == (int64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_self->start_offset = __pyx_t_28;
      goto __pyx_L87;
    }
    __pyx_L87:;
    goto __pyx_L73;
  }
  __pyx_L73:;

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

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

/* "pysam/calignmentfile.pyx":555
 *                 self.start_offset = self.tell()
 * 
 *     def gettid(self, reference):             # <<<<<<<<<<<<<<
 *         '''
 *         convert :term:`reference` name into numerical :term:`tid`
 */

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

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

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

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

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

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

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

  /* "pysam/calignmentfile.pyx":555
 *                 self.start_offset = self.tell()
 * 
 *     def gettid(self, reference):             # <<<<<<<<<<<<<<
 *         '''
 *         convert :term:`reference` name into numerical :term:`tid`
 */

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

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

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_11getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_10getrname[] = "AlignmentFile.getrname(self, tid)\n\n        convert numerical :term:`tid` into :term:`reference` name.";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_11getrname(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getrname (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_10getrname(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), ((PyObject *)__pyx_v_tid));

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

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

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

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

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

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

    /* "pysam/calignmentfile.pyx":572
 *             raise ValueError("I/O operation on closed file")
 *         if not 0 <= tid < self.header.n_targets:
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %             # <<<<<<<<<<<<<<
 *                              (tid, self.header.n_targets))
 *         return _charptr_to_str(self.header.target_name[tid])
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_reference_id_i_out_of_range_0_ti, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":574
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 *                              (tid, self.header.n_targets))
 *         return _charptr_to_str(self.header.target_name[tid])             # <<<<<<<<<<<<<<
 * 
 *     cdef char * _getrname(self, int tid):   # TODO unused
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_6 = __Pyx_PyIndex_AsSsize_t(__pyx_v_tid); if (unlikely((__pyx_t_6 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile__charptr_to_str((__pyx_v_self->header->target_name[__pyx_t_6])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

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

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

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

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

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

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

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

    /* "pysam/calignmentfile.pyx":583
 * 
 *         if not 0 <= tid < self.header.n_targets:
 *             raise ValueError("tid %i out of range 0<=tid<%i" %             # <<<<<<<<<<<<<<
 *                              (tid, self.header.n_targets ))
 *         return self.header.target_name[tid]
 */
    __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_tid_i_out_of_range_0_tid_i, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

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

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

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

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_13_parseRegion(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_12_parseRegion[] = "AlignmentFile._parseRegion(self, reference=None, start=None, end=None, region=None, tid=None)\nparse region information.\n\n        Raises ValueError for invalid regions.\n\n        Returns a tuple of a flag, :term:`tid`, start and end. The\n        flag indicates whether some coordinates were supplied.\n\n        Note that region strings are 1-based, while *start* and *end* denote\n        an interval in python coordinates.\n\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_13_parseRegion(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_tid = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_parseRegion (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,&__pyx_n_s_tid,0};
    PyObject* values[5] = {0,0,0,0,0};

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

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

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

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

    /* "pysam/calignmentfile.pyx":592
 *                      end=None,
 *                      region=None,
 *                      tid=None):             # <<<<<<<<<<<<<<
 *         '''parse region information.
 * 
 */
    values[4] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reference);
          if (value) { values[0] = value; kw_args--; }
        }
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_region);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tid);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_parseRegion") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 587; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
    __pyx_v_tid = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_parseRegion", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 587; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile._parseRegion", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_12_parseRegion(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_tid);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /* "pysam/calignmentfile.pyx":625
 *         if region:
 *             region = _forceStr(region)
 *             parts = re.split("[:-]", region)             # <<<<<<<<<<<<<<
 *             reference = parts[0]
 *             if len(parts) >= 2:
 */
    __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_split); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    __pyx_t_12 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
        __pyx_t_12 = 1;
      }
    }
    __pyx_t_10 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    if (__pyx_t_8) {
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = NULL;
    }
    __Pyx_INCREF(__pyx_kp_s__13);
    PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_12, __pyx_kp_s__13);
    __Pyx_GIVEREF(__pyx_kp_s__13);
    __Pyx_INCREF(__pyx_v_region);
    PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_12, __pyx_v_region);
    __Pyx_GIVEREF(__pyx_v_region);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_parts = __pyx_t_1;
    __pyx_t_1 = 0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  /* "pysam/calignmentfile.pyx":646
 *             raise ValueError(
 *                 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend))
 *         if not 0 <= rstart < max_pos:             # <<<<<<<<<<<<<<
 *             raise ValueError('start out of range (%i)' % rstart)
 *         if not 0 <= rend <= max_pos:
 */
  __pyx_t_2 = (0 <= __pyx_v_rstart);
  if (__pyx_t_2) {
    __pyx_t_2 = (__pyx_v_rstart < __pyx_v_5pysam_14calignmentfile_max_pos);
  }
  __pyx_t_13 = ((!(__pyx_t_2 != 0)) != 0);
  if (__pyx_t_13) {

    /* "pysam/calignmentfile.pyx":647
 *                 'invalid coordinates: start (%i) > end (%i)' % (rstart, rend))
 *         if not 0 <= rstart < max_pos:
 *             raise ValueError('start out of range (%i)' % rstart)             # <<<<<<<<<<<<<<
 *         if not 0 <= rend <= max_pos:
 *             raise ValueError('end out of range (%i)' % rend)
 */
    __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rstart); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_start_out_of_range_i, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_8);
    __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_Raise(__pyx_t_8, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 647; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":648
 *         if not 0 <= rstart < max_pos:
 *             raise ValueError('start out of range (%i)' % rstart)
 *         if not 0 <= rend <= max_pos:             # <<<<<<<<<<<<<<
 *             raise ValueError('end out of range (%i)' % rend)
 * 
 */
  __pyx_t_13 = (0 <= __pyx_v_rend);
  if (__pyx_t_13) {
    __pyx_t_13 = (__pyx_v_rend <= __pyx_v_5pysam_14calignmentfile_max_pos);
  }
  __pyx_t_2 = ((!(__pyx_t_13 != 0)) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":649
 *             raise ValueError('start out of range (%i)' % rstart)
 *         if not 0 <= rend <= max_pos:
 *             raise ValueError('end out of range (%i)' % rend)             # <<<<<<<<<<<<<<
 * 
 *         return 1, rtid, rstart, rend
 */
    __pyx_t_8 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_rend); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_end_out_of_range_i, __pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 649; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

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

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

/* "pysam/calignmentfile.pyx":653
 *         return 1, rtid, rstart, rend
 * 
 *     def reset(self):             # <<<<<<<<<<<<<<
 *         '''reset file position to beginning of file just after
 *         the header.'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_15reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_14reset[] = "AlignmentFile.reset(self)\nreset file position to beginning of file just after\n        the header.";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_15reset(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("reset (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_14reset(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_14reset(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("reset", 0);
  __Pyx_TraceCall("reset", __pyx_f[0], 653);

  /* "pysam/calignmentfile.pyx":656
 *         '''reset file position to beginning of file just after
 *         the header.'''
 *         return self.seek(self.start_offset, 0)             # <<<<<<<<<<<<<<
 * 
 *     def seek(self, uint64_t offset, int where = 0):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_seek); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_int64_t(__pyx_v_self->start_offset); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && 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 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_4) {
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
  }
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_t_3 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":653
 *         return 1, rtid, rstart, rend
 * 
 *     def reset(self):             # <<<<<<<<<<<<<<
 *         '''reset file position to beginning of file just after
 *         the header.'''
 */

  /* 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_6);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.reset", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_17seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_16seek[] = "AlignmentFile.seek(self, uint64_t offset, int where=0)\nmove file pointer to position *offset*, see\n        :meth:`pysam.AlignmentFile.tell`.\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_17seek(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  uint64_t __pyx_v_offset;
  int __pyx_v_where;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("seek (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_offset,&__pyx_n_s_where,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_offset)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_where);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "seek") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_offset = __Pyx_PyInt_As_uint64_t(values[0]); if (unlikely((__pyx_v_offset == (uint64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    if (values[1]) {
      __pyx_v_where = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_where == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_where = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("seek", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.seek", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_16seek(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_offset, __pyx_v_where);

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

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

  /* "pysam/calignmentfile.pyx":663
 *         '''
 * 
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":664
 * 
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not self.is_bam:
 *             raise NotImplementedError(
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

    /* "pysam/calignmentfile.pyx":666
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "seek only available in bam files")
 *         if self.is_stream:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":668
 *             raise NotImplementedError(
 *                 "seek only available in bam files")
 *         if self.is_stream:             # <<<<<<<<<<<<<<
 *             raise OSError("seek no available in streams")
 * 
 */
  __pyx_t_5 = (__pyx_v_self->is_stream != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":669
 *                 "seek only available in bam files")
 *         if self.is_stream:
 *             raise OSError("seek no available in streams")             # <<<<<<<<<<<<<<
 * 
 *         return bgzf_seek(hts_get_bgzfp(self.htsfile), offset, where)
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_OSError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

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

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

/* "pysam/calignmentfile.pyx":673
 *         return bgzf_seek(hts_get_bgzfp(self.htsfile), offset, where)
 * 
 *     def tell(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return current file position.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_19tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_18tell[] = "AlignmentFile.tell(self)\n\n        return current file position.\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_19tell(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("tell (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_18tell(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":677
 *         return current file position.
 *         '''
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 *         if not (self.is_bam or self.is_cram):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":678
 *         '''
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not (self.is_bam or self.is_cram):
 *             raise NotImplementedError(
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":679
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")
 *         if not (self.is_bam or self.is_cram):             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "seek only available in bam files")
 */
  __pyx_t_4 = (__pyx_v_self->is_bam != 0);
  if (!__pyx_t_4) {
  } else {
    __pyx_t_5 = __pyx_t_4;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_self->is_cram != 0);
  __pyx_t_5 = __pyx_t_4;
  __pyx_L5_bool_binop_done:;
  __pyx_t_4 = ((!__pyx_t_5) != 0);
  if (__pyx_t_4) {

    /* "pysam/calignmentfile.pyx":680
 *             raise ValueError("I/O operation on closed file")
 *         if not (self.is_bam or self.is_cram):
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "seek only available in bam files")
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

  /* "pysam/calignmentfile.pyx":673
 *         return bgzf_seek(hts_get_bgzfp(self.htsfile), offset, where)
 * 
 *     def tell(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return current file position.
 */

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

/* "pysam/calignmentfile.pyx":685
 *         return bgzf_tell(hts_get_bgzfp(self.htsfile))
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_21fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_20fetch[] = "AlignmentFile.fetch(self, reference=None, start=None, end=None, region=None, tid=None, callback=None, until_eof=False, multiple_iterators=False)\nfetch aligned, i.e. mapped, reads in a :term:`region`\n        using 0-based\n        indexing. The region is specified by :term:`reference`,\n        *start* and *end*. Alternatively, a samtools :term:`region`\n        string can be supplied.\n\n        Without *reference* or *region* all mapped reads will be\n        fetched. The reads will be returned ordered by reference\n        sequence, which will not necessarily be the order within the\n        file. \n\n        If *until_eof* is given, all reads from the current file\n        position will be returned in order as they are within the\n        file. Using this option will also fetch unmapped reads.\n\n        Set *multiple_iterators* to true if you will be using multiple\n        iterators on the same file at the same time. The iterator\n        returned will receive its own copy of a filehandle to the file\n        effectively re-opening the file. Re-opening a file creates\n        some overhead, so beware.\n\n        If only *reference* is set, all reads aligned to *reference*\n        will be fetched.\n\n        Note that a :term:`SAM` file does not allow random access. If\n        *region* or *reference* are given, an exception is raised.\n\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_21fetch(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_reference = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_region = 0;
  PyObject *__pyx_v_tid = 0;
  PyObject *__pyx_v_callback = 0;
  PyObject *__pyx_v_until_eof = 0;
  PyObject *__pyx_v_multiple_iterators = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("fetch (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_reference,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_region,&__pyx_n_s_tid,&__pyx_n_s_callback,&__pyx_n_s_until_eof,&__pyx_n_s_multiple_iterators,0};
    PyObject* values[8] = {0,0,0,0,0,0,0,0};

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

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

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

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

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

    /* "pysam/calignmentfile.pyx":691
 *               region=None,
 *               tid=None,
 *               callback=None,             # <<<<<<<<<<<<<<
 *               until_eof=False,
 *               multiple_iterators=False):
 */
    values[5] = ((PyObject *)Py_None);

    /* "pysam/calignmentfile.pyx":692
 *               tid=None,
 *               callback=None,
 *               until_eof=False,             # <<<<<<<<<<<<<<
 *               multiple_iterators=False):
 *         '''fetch aligned, i.e. mapped, reads in a :term:`region`
 */
    values[6] = ((PyObject *)Py_False);

    /* "pysam/calignmentfile.pyx":693
 *               callback=None,
 *               until_eof=False,
 *               multiple_iterators=False):             # <<<<<<<<<<<<<<
 *         '''fetch aligned, i.e. mapped, reads in a :term:`region`
 *         using 0-based
 */
    values[7] = ((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  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reference);
          if (value) { values[0] = value; kw_args--; }
        }
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_region);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tid);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_callback);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_until_eof);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_multiple_iterators);
          if (value) { values[7] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fetch") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
    __pyx_v_tid = values[4];
    __pyx_v_callback = values[5];
    __pyx_v_until_eof = values[6];
    __pyx_v_multiple_iterators = values[7];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("fetch", 0, 0, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.fetch", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_20fetch(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_tid, __pyx_v_callback, __pyx_v_until_eof, __pyx_v_multiple_iterators);

  /* "pysam/calignmentfile.pyx":685
 *         return bgzf_tell(hts_get_bgzfp(self.htsfile))
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_20fetch(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_tid, PyObject *__pyx_v_callback, PyObject *__pyx_v_until_eof, PyObject *__pyx_v_multiple_iterators) {
  int __pyx_v_rtid;
  int __pyx_v_rstart;
  int __pyx_v_rend;
  int __pyx_v_has_coord;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *(*__pyx_t_10)(PyObject *);
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  int __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("fetch", 0);
  __Pyx_TraceCall("fetch", __pyx_f[0], 685);
  __Pyx_INCREF(__pyx_v_multiple_iterators);

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

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

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

  /* "pysam/calignmentfile.pyx":731
 *                                                           end,
 *                                                           region,
 *                                                           tid)             # <<<<<<<<<<<<<<
 * 
 *         # Turn of re-opening if htsfile is a stream
 */
  __pyx_t_3 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && 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_6 = 1;
    }
  }
  __pyx_t_7 = PyTuple_New(5+__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (__pyx_t_3) {
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
  }
  __Pyx_INCREF(__pyx_v_reference);
  PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_reference);
  __Pyx_GIVEREF(__pyx_v_reference);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_v_end);
  __Pyx_GIVEREF(__pyx_v_end);
  __Pyx_INCREF(__pyx_v_region);
  PyTuple_SET_ITEM(__pyx_t_7, 3+__pyx_t_6, __pyx_v_region);
  __Pyx_GIVEREF(__pyx_v_region);
  __Pyx_INCREF(__pyx_v_tid);
  PyTuple_SET_ITEM(__pyx_t_7, 4+__pyx_t_6, __pyx_v_tid);
  __Pyx_GIVEREF(__pyx_v_tid);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_8 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_8 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_8);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_7,&__pyx_t_3,&__pyx_t_8};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_7,&__pyx_t_3,&__pyx_t_8};
    __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext;
    for (index=0; index < 4; index++) {
      PyObject* item = __pyx_t_10(__pyx_t_9); if (unlikely(!item)) goto __pyx_L4_unpacking_failed;
      __Pyx_GOTREF(item);
      *(temps[index]) = item;
    }
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_10 = NULL;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_10 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }

  /* "pysam/calignmentfile.pyx":727
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(reference,             # <<<<<<<<<<<<<<
 *                                                           start,
 *                                                           end,
 */
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 727; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_has_coord = __pyx_t_11;
  __pyx_v_rtid = __pyx_t_12;
  __pyx_v_rstart = __pyx_t_13;
  __pyx_v_rend = __pyx_t_14;

  /* "pysam/calignmentfile.pyx":734
 * 
 *         # Turn of re-opening if htsfile is a stream
 *         if self.is_stream:             # <<<<<<<<<<<<<<
 *             multiple_iterators = False
 * 
 */
  __pyx_t_5 = (__pyx_v_self->is_stream != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":735
 *         # 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);
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "pysam/calignmentfile.pyx":737
 *             multiple_iterators = False
 * 
 *         if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *             if not until_eof and not self.is_remote:
 *                 if not self._hasIndex():
 */
  __pyx_t_4 = (__pyx_v_self->is_bam != 0);
  if (!__pyx_t_4) {
  } else {
    __pyx_t_5 = __pyx_t_4;
    goto __pyx_L8_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_self->is_cram != 0);
  __pyx_t_5 = __pyx_t_4;
  __pyx_L8_bool_binop_done:;
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":738
 * 
 *         if self.is_bam or self.is_cram:
 *             if not until_eof and not self.is_remote:             # <<<<<<<<<<<<<<
 *                 if not self._hasIndex():
 *                     raise ValueError(
 */
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_until_eof); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_15 = ((!__pyx_t_4) != 0);
    if (__pyx_t_15) {
    } else {
      __pyx_t_5 = __pyx_t_15;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_15 = ((!(__pyx_v_self->is_remote != 0)) != 0);
    __pyx_t_5 = __pyx_t_15;
    __pyx_L11_bool_binop_done:;
    if (__pyx_t_5) {

      /* "pysam/calignmentfile.pyx":739
 *         if self.is_bam or self.is_cram:
 *             if not until_eof and not self.is_remote:
 *                 if not self._hasIndex():             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "fetch called on bamfile without index")
 */
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_hasIndex); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      if (__pyx_t_3) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_15 = ((!__pyx_t_5) != 0);
      if (__pyx_t_15) {

        /* "pysam/calignmentfile.pyx":740
 *             if not until_eof and not self.is_remote:
 *                 if not self._hasIndex():
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "fetch called on bamfile without index")
 * 
 */
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_Raise(__pyx_t_1, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "pysam/calignmentfile.pyx":743
 *                         "fetch called on bamfile without index")
 * 
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 return IteratorRowRegion(
 *                     self, rtid, rstart, rend,
 */
    __pyx_t_15 = (__pyx_v_has_coord != 0);
    if (__pyx_t_15) {

      /* "pysam/calignmentfile.pyx":744
 * 
 *             if has_coord:
 *                 return IteratorRowRegion(             # <<<<<<<<<<<<<<
 *                     self, rtid, rstart, rend,
 *                     multiple_iterators=multiple_iterators)
 */
      __Pyx_XDECREF(__pyx_r);

      /* "pysam/calignmentfile.pyx":745
 *             if has_coord:
 *                 return IteratorRowRegion(
 *                     self, rtid, rstart, rend,             # <<<<<<<<<<<<<<
 *                     multiple_iterators=multiple_iterators)
 *             else:
 */
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_rtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_v_rstart); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_rend); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);

      /* "pysam/calignmentfile.pyx":744
 * 
 *             if has_coord:
 *                 return IteratorRowRegion(             # <<<<<<<<<<<<<<
 *                     self, rtid, rstart, rend,
 *                     multiple_iterators=multiple_iterators)
 */
      __pyx_t_7 = PyTuple_New(4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_7, 3, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      __pyx_t_1 = 0;
      __pyx_t_8 = 0;
      __pyx_t_3 = 0;
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);

      /* "pysam/calignmentfile.pyx":746
 *                 return IteratorRowRegion(
 *                     self, rtid, rstart, rend,
 *                     multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 *             else:
 *                 if until_eof:
 */
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysam/calignmentfile.pyx":744
 * 
 *             if has_coord:
 *                 return IteratorRowRegion(             # <<<<<<<<<<<<<<
 *                     self, rtid, rstart, rend,
 *                     multiple_iterators=multiple_iterators)
 */
      __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion)), __pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_8;
      __pyx_t_8 = 0;
      goto __pyx_L0;
    }
    /*else*/ {

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

        /* "pysam/calignmentfile.pyx":749
 *             else:
 *                 if until_eof:
 *                     return IteratorRowAll(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __Pyx_XDECREF(__pyx_r);

        /* "pysam/calignmentfile.pyx":750
 *                 if until_eof:
 *                     return IteratorRowAll(
 *                         self,             # <<<<<<<<<<<<<<
 *                         multiple_iterators=multiple_iterators)
 *                 else:
 */
        __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_INCREF(((PyObject *)__pyx_v_self));
        PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_self));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_self));

        /* "pysam/calignmentfile.pyx":749
 *             else:
 *                 if until_eof:
 *                     return IteratorRowAll(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);

        /* "pysam/calignmentfile.pyx":751
 *                     return IteratorRowAll(
 *                         self,
 *                         multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 *                 else:
 *                     # AH: check - reason why no multiple_iterators for
 */
        if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "pysam/calignmentfile.pyx":749
 *             else:
 *                 if until_eof:
 *                     return IteratorRowAll(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRowAll)), __pyx_t_8, __pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_r = __pyx_t_7;
        __pyx_t_7 = 0;
        goto __pyx_L0;
      }
      /*else*/ {

        /* "pysam/calignmentfile.pyx":755
 *                     # AH: check - reason why no multiple_iterators for
 *                     # AllRefs?
 *                     return IteratorRowAllRefs(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __Pyx_XDECREF(__pyx_r);

        /* "pysam/calignmentfile.pyx":756
 *                     # AllRefs?
 *                     return IteratorRowAllRefs(
 *                         self,             # <<<<<<<<<<<<<<
 *                         multiple_iterators=multiple_iterators)
 *         else:
 */
        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(((PyObject *)__pyx_v_self));
        PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_self));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_self));

        /* "pysam/calignmentfile.pyx":755
 *                     # AH: check - reason why no multiple_iterators for
 *                     # AllRefs?
 *                     return IteratorRowAllRefs(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);

        /* "pysam/calignmentfile.pyx":757
 *                     return IteratorRowAllRefs(
 *                         self,
 *                         multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 *         else:
 *             if has_coord:
 */
        if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "pysam/calignmentfile.pyx":755
 *                     # AH: check - reason why no multiple_iterators for
 *                     # AllRefs?
 *                     return IteratorRowAllRefs(             # <<<<<<<<<<<<<<
 *                         self,
 *                         multiple_iterators=multiple_iterators)
 */
        __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRowAllRefs)), __pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_r = __pyx_t_8;
        __pyx_t_8 = 0;
        goto __pyx_L0;
      }
    }
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":759
 *                         multiple_iterators=multiple_iterators)
 *         else:
 *             if has_coord:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "fetching by region is not available for sam files")
 */
    __pyx_t_15 = (__pyx_v_has_coord != 0);
    if (__pyx_t_15) {

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

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

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

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

      /* "pysam/calignmentfile.pyx":768
 * 
 *             if self.header == NULL:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "fetch called for htsfile without header")
 * 
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

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

      /* "pysam/calignmentfile.pyx":774
 *             # give warning, sam_read1 segfaults
 *             if self.header.n_targets == 0:
 *                 warnings.warn("fetch called for htsfile without header")             # <<<<<<<<<<<<<<
 * 
 *             return IteratorRowAll(self,
 */
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_warnings); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_warn); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      goto __pyx_L19;
    }
    __pyx_L19:;

    /* "pysam/calignmentfile.pyx":776
 *                 warnings.warn("fetch called for htsfile without header")
 * 
 *             return IteratorRowAll(self,             # <<<<<<<<<<<<<<
 *                                   multiple_iterators=multiple_iterators)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)__pyx_v_self));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/calignmentfile.pyx":777
 * 
 *             return IteratorRowAll(self,
 *                                   multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *     def head(self, n, multiple_iterators=True):
 */
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignmentfile.pyx":776
 *                 warnings.warn("fetch called for htsfile without header")
 * 
 *             return IteratorRowAll(self,             # <<<<<<<<<<<<<<
 *                                   multiple_iterators=multiple_iterators)
 * 
 */
    __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRowAll)), __pyx_t_8, __pyx_t_3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_7;
    __pyx_t_7 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":685
 *         return bgzf_tell(hts_get_bgzfp(self.htsfile))
 * 
 *     def fetch(self,             # <<<<<<<<<<<<<<
 *               reference=None,
 *               start=None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.calignmentfile.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);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":779
 *                                   multiple_iterators=multiple_iterators)
 * 
 *     def head(self, n, multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         '''return iterator over the first n alignments.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_23head(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_22head[] = "AlignmentFile.head(self, n, multiple_iterators=True)\nreturn iterator over the first n alignments. \n\n        This is useful for inspecting the bam-file.\n\n        *multiple_iterators* is set to True by default in order to\n        avoid changing the current file position.\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_23head(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);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_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_filename = __pyx_f[0]; __pyx_lineno = 779; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.head", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_22head(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_n, __pyx_v_multiple_iterators);

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

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

  /* "pysam/calignmentfile.pyx":787
 *         avoid changing the current file position.
 *         '''
 *         return IteratorRowHead(self, n,             # <<<<<<<<<<<<<<
 *                                multiple_iterators=multiple_iterators)
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(__pyx_v_n);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_n);
  __Pyx_GIVEREF(__pyx_v_n);
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/calignmentfile.pyx":788
 *         '''
 *         return IteratorRowHead(self, n,
 *                                multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *     def mate(self,
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":787
 *         avoid changing the current file position.
 *         '''
 *         return IteratorRowHead(self, n,             # <<<<<<<<<<<<<<
 *                                multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRowHead)), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":779
 *                                   multiple_iterators=multiple_iterators)
 * 
 *     def head(self, n, multiple_iterators=True):             # <<<<<<<<<<<<<<
 *         '''return 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.calignmentfile.AlignmentFile.head", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":790
 *                                multiple_iterators=multiple_iterators)
 * 
 *     def mate(self,             # <<<<<<<<<<<<<<
 *              AlignedSegment read):
 *         '''return the mate of :class:`AlignedSegment` *read*.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_25mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_24mate[] = "AlignmentFile.mate(self, AlignedSegment read)\nreturn the mate of :class:`AlignedSegment` *read*.\n\n        Throws a ValueError if read is unpaired or the mate\n        is unmapped.\n\n        .. note::\n\n            Calling this method will change the file position.\n            This might interfere with any iterators that have\n            not re-opened the file.\n\n        .. note::\n  \n           This method is too slow for high-throughput processing.\n           If a read needs to be processed with its mate, work\n           from a read name sorted file or, better, cache reads.\n\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_25mate(PyObject *__pyx_v_self, PyObject *__pyx_v_read) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("mate (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_14calignmentfile_AlignedSegment, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 791; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_24mate(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), ((struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_13AlignmentFile_24mate(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_read) {
  uint32_t __pyx_v_flag;
  int __pyx_v_x;
  PyObject *__pyx_v_mate = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("mate", 0);
  __Pyx_TraceCall("mate", __pyx_f[0], 790);

  /* "pysam/calignmentfile.pyx":810
 * 
 *         '''
 *         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/calignmentfile.pyx":812
 *         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 (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":814
 *         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_filename = __pyx_f[0]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/calignmentfile.pyx":813
 * 
 *         if flag & BAM_FPAIRED == 0:
 *             raise ValueError("read %s: is unpaired" %             # <<<<<<<<<<<<<<
 *                              (read.query_name))
 *         if flag & BAM_FMUNMAP != 0:
 */
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_read_s_is_unpaired, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":815
 *             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 (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":817
 *         if flag & BAM_FMUNMAP != 0:
 *             raise ValueError("mate %s: is unmapped" %
 *                              (read.query_name))             # <<<<<<<<<<<<<<
 * 
 *         # xor flags to get the other mate
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);

    /* "pysam/calignmentfile.pyx":816
 *                              (read.query_name))
 *         if flag & BAM_FMUNMAP != 0:
 *             raise ValueError("mate %s: is unmapped" %             # <<<<<<<<<<<<<<
 *                              (read.query_name))
 * 
 */
    __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_mate_s_is_unmapped, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":820
 * 
 *         # 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/calignmentfile.pyx":821
 *         # 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/calignmentfile.pyx":829
 *         # 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_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/calignmentfile.pyx":830
 *         # 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_filename = __pyx_f[0]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/calignmentfile.pyx":831
 *         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_filename = __pyx_f[0]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/calignmentfile.pyx":829
 *         # 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_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/calignmentfile.pyx":832
 *                 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_4 = __Pyx_PyInt_From_int32_t(__pyx_v_read->_delegate->core.mtid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_tid, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":833
 *                 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_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":829
 *         # 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_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (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_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __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_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_5, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_8(__pyx_t_5);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_mate, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "pysam/calignmentfile.pyx":834
 *                 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_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_uint32_t(__pyx_v_flag); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PyNumber_And(__pyx_t_4, __pyx_t_6); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __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_filename = __pyx_f[0]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __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/calignmentfile.pyx":835
 *                 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_filename = __pyx_f[0]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_read), __pyx_n_s_query_name); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_6, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = __pyx_t_9;
    __pyx_L8_bool_binop_done:;
    if (__pyx_t_2) {

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

    /* "pysam/calignmentfile.pyx":829
 *         # 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/calignmentfile.pyx":838
 *                 break
 *         else:
 *             raise ValueError("mate not found")             # <<<<<<<<<<<<<<
 * 
 *         return mate
 */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":829
 *         # 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/calignmentfile.pyx":840
 *             raise ValueError("mate not found")
 * 
 *         return mate             # <<<<<<<<<<<<<<
 * 
 *     def count(self,
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_mate);
  __pyx_r = __pyx_v_mate;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":790
 *                                multiple_iterators=multiple_iterators)
 * 
 *     def mate(self,             # <<<<<<<<<<<<<<
 *              AlignedSegment read):
 *         '''return the mate of :class:`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.calignmentfile.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);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

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

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

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

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

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

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

    /* "pysam/calignmentfile.pyx":847
 *               end=None,
 *               region=None,
 *               until_eof=False):             # <<<<<<<<<<<<<<
 *         '''*(reference = None, start = None, end = None,
 *         region = None, callback = None, until_eof = False)*
 */
    values[4] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reference);
          if (value) { values[0] = value; kw_args--; }
        }
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_region);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_until_eof);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
    __pyx_v_until_eof = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("count", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.count", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_26count(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_until_eof);

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

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

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

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

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

    /* "pysam/calignmentfile.pyx":863
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         for read in self.fetch(reference=reference,
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

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

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

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

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

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

    /* "pysam/calignmentfile.pyx":870
 *                                region=region,
 *                                until_eof=until_eof):
 *             counter += 1             # <<<<<<<<<<<<<<
 * 
 *         return counter
 */
    __pyx_v_counter = (__pyx_v_counter + 1);

    /* "pysam/calignmentfile.pyx":865
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         for read in self.fetch(reference=reference,             # <<<<<<<<<<<<<<
 *                                start=start,
 *                                end=end,
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

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

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

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

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

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

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

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

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

    /* "pysam/calignmentfile.pyx":878
 *                 start = None,
 *                 end = None,
 *                 region = None,             # <<<<<<<<<<<<<<
 *                 **kwargs ):
 *         '''perform a :term:`pileup` within a :term:`region`. The region is
 */
    values[3] = ((PyObject *)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reference);
          if (value) { values[0] = value; kw_args--; }
        }
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_region);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "pileup") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_reference = values[0];
    __pyx_v_start = values[1];
    __pyx_v_end = values[2];
    __pyx_v_region = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("pileup", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 874; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_28pileup(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_reference, __pyx_v_start, __pyx_v_end, __pyx_v_region, __pyx_v_kwargs);

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

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_28pileup(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_reference, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_region, PyObject *__pyx_v_kwargs) {
  int __pyx_v_rtid;
  int __pyx_v_rstart;
  int __pyx_v_rend;
  int __pyx_v_has_coord;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *(*__pyx_t_10)(PyObject *);
  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_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("pileup", 0);
  __Pyx_TraceCall("pileup", __pyx_f[0], 874);

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

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

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

  /* "pysam/calignmentfile.pyx":949
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(
 *             reference, start, end, region )             # <<<<<<<<<<<<<<
 * 
 *         if self.is_bam or self.is_cram:
 */
  __pyx_t_3 = NULL;
  __pyx_t_6 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && 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_6 = 1;
    }
  }
  __pyx_t_7 = PyTuple_New(4+__pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  if (__pyx_t_3) {
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
  }
  __Pyx_INCREF(__pyx_v_reference);
  PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_reference);
  __Pyx_GIVEREF(__pyx_v_reference);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_v_end);
  __Pyx_GIVEREF(__pyx_v_end);
  __Pyx_INCREF(__pyx_v_region);
  PyTuple_SET_ITEM(__pyx_t_7, 3+__pyx_t_6, __pyx_v_region);
  __Pyx_GIVEREF(__pyx_v_region);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    #if CYTHON_COMPILING_IN_CPYTHON
    Py_ssize_t size = Py_SIZE(sequence);
    #else
    Py_ssize_t size = PySequence_Size(sequence);
    #endif
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_8 = PyTuple_GET_ITEM(sequence, 3); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
      __pyx_t_8 = PyList_GET_ITEM(sequence, 3); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_8);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_7,&__pyx_t_3,&__pyx_t_8};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    Py_ssize_t index = -1;
    PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_7,&__pyx_t_3,&__pyx_t_8};
    __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext;
    for (index=0; index < 4; index++) {
      PyObject* item = __pyx_t_10(__pyx_t_9); if (unlikely(!item)) goto __pyx_L4_unpacking_failed;
      __Pyx_GOTREF(item);
      *(temps[index]) = item;
    }
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_10 = NULL;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_10 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }

  /* "pysam/calignmentfile.pyx":948
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(             # <<<<<<<<<<<<<<
 *             reference, start, end, region )
 * 
 */
  __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_13 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_14 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_14 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_has_coord = __pyx_t_11;
  __pyx_v_rtid = __pyx_t_12;
  __pyx_v_rstart = __pyx_t_13;
  __pyx_v_rend = __pyx_t_14;

  /* "pysam/calignmentfile.pyx":951
 *             reference, start, end, region )
 * 
 *         if self.is_bam or self.is_cram:             # <<<<<<<<<<<<<<
 *             if not self._hasIndex():
 *                 raise ValueError("no index available for pileup")
 */
  __pyx_t_4 = (__pyx_v_self->is_bam != 0);
  if (!__pyx_t_4) {
  } else {
    __pyx_t_5 = __pyx_t_4;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_self->is_cram != 0);
  __pyx_t_5 = __pyx_t_4;
  __pyx_L7_bool_binop_done:;
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":952
 * 
 *         if self.is_bam or self.is_cram:
 *             if not self._hasIndex():             # <<<<<<<<<<<<<<
 *                 raise ValueError("no index available for pileup")
 * 
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_hasIndex); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    if (__pyx_t_3) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = ((!__pyx_t_5) != 0);
    if (__pyx_t_4) {

      /* "pysam/calignmentfile.pyx":953
 *         if self.is_bam or self.is_cram:
 *             if not self._hasIndex():
 *                 raise ValueError("no index available for pileup")             # <<<<<<<<<<<<<<
 * 
 *             if has_coord:
 */
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_Raise(__pyx_t_1, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

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

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

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

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

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

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

      /* "pysam/calignmentfile.pyx":956
 * 
 *             if has_coord:
 *                 return IteratorColumnRegion(self,             # <<<<<<<<<<<<<<
 *                                             tid = rtid,
 *                                             start = rstart,
 */
      __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorColumnRegion)), __pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_r = __pyx_t_3;
      __pyx_t_3 = 0;
      goto __pyx_L0;
    }
    /*else*/ {

      /* "pysam/calignmentfile.pyx":962
 *                                             **kwargs )
 *             else:
 *                 return IteratorColumnAllRefs(self, **kwargs )             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      __pyx_t_8 = __pyx_v_kwargs;
      __Pyx_INCREF(__pyx_t_8);
      __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorColumnAllRefs)), __pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;
    }
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":965
 * 
 *         else:
 *             raise NotImplementedError( "pileup of samfiles not implemented yet" )             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.pileup", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":968
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking
 *     def count_coverage(self, chr, start, stop, quality_threshold = 15,             # <<<<<<<<<<<<<<
 *                        read_callback = 'all'):
 *         """Count ACGT in a part of a AlignmentFile.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_31count_coverage(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_30count_coverage[] = "AlignmentFile.count_coverage(self, chr, start, stop, quality_threshold=15, read_callback='all')\nCount ACGT in a part of a AlignmentFile. \n        Return 4 array.arrays of length = stop - start,\n        in order A C G T.\n        \n        @quality_threshold is the minimum quality score (in phred) a\n        base has to reach to be counted.  Possible @read_callback\n        values are\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 ```check_read(read)``1\n        that should return True only for those reads that shall be included in\n        the counting.\n\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_31count_coverage(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_chr = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_stop = 0;
  PyObject *__pyx_v_quality_threshold = 0;
  PyObject *__pyx_v_read_callback = 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_chr,&__pyx_n_s_start,&__pyx_n_s_stop,&__pyx_n_s_quality_threshold,&__pyx_n_s_read_callback,0};
    PyObject* values[5] = {0,0,0,0,0};
    values[3] = ((PyObject *)__pyx_int_15);
    values[4] = ((PyObject *)__pyx_n_s_all);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chr)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("count_coverage", 0, 3, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_stop)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("count_coverage", 0, 3, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_quality_threshold);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_read_callback);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "count_coverage") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_chr = values[0];
    __pyx_v_start = values[1];
    __pyx_v_stop = values[2];
    __pyx_v_quality_threshold = values[3];
    __pyx_v_read_callback = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("count_coverage", 0, 3, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 968; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.count_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_30count_coverage(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_chr, __pyx_v_start, __pyx_v_stop, __pyx_v_quality_threshold, __pyx_v_read_callback);

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_30count_coverage(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_chr, PyObject *__pyx_v_start, PyObject *__pyx_v_stop, PyObject *__pyx_v_quality_threshold, PyObject *__pyx_v_read_callback) {
  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;
  char *__pyx_v_seq;
  arrayobject *__pyx_v_quality = 0;
  int __pyx_v_qpos;
  int __pyx_v_refpos;
  CYTHON_UNUSED int __pyx_v_c;
  CYTHON_UNUSED int __pyx_v__threshold;
  PyObject *__pyx_v_read = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  char *__pyx_t_11;
  Py_ssize_t __pyx_t_12;
  PyObject *(*__pyx_t_13)(PyObject *);
  PyObject *__pyx_t_14 = NULL;
  PyObject *(*__pyx_t_15)(PyObject *);
  int __pyx_t_16;
  int __pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("count_coverage", 0);
  __Pyx_TraceCall("count_coverage", __pyx_f[0], 968);

  /* "pysam/calignmentfile.pyx":992
 *         """
 * 
 *         cdef int _start = start             # <<<<<<<<<<<<<<
 *         cdef int _stop = stop
 *         cdef int length = _stop - _start
 */
  __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_start); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 992; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v__start = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":993
 * 
 *         cdef int _start = start
 *         cdef int _stop = stop             # <<<<<<<<<<<<<<
 *         cdef int length = _stop - _start
 *         cdef array.array int_array_template = array.array('L', [])
 */
  __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_stop); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v__stop = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":994
 *         cdef int _start = start
 *         cdef int _stop = stop
 *         cdef int length = _stop - _start             # <<<<<<<<<<<<<<
 *         cdef array.array int_array_template = array.array('L', [])
 *         cdef array.array count_a
 */
  __pyx_v_length = (__pyx_v__stop - __pyx_v__start);

  /* "pysam/calignmentfile.pyx":995
 *         cdef int _stop = stop
 *         cdef int length = _stop - _start
 *         cdef array.array int_array_template = array.array('L', [])             # <<<<<<<<<<<<<<
 *         cdef array.array count_a
 *         cdef array.array count_c
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_n_s_L);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_L);
  __Pyx_GIVEREF(__pyx_n_s_L);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7cpython_5array_array)), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_int_array_template = ((arrayobject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":1000
 *         cdef array.array count_g
 *         cdef array.array count_t
 *         count_a = array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 *         count_c = array.clone(int_array_template, length, zero=True)
 *         count_g = array.clone(int_array_template, length, zero=True)
 */
  __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_count_a = ((arrayobject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":1001
 *         cdef array.array count_t
 *         count_a = array.clone(int_array_template, length, zero=True)
 *         count_c = array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 *         count_g = array.clone(int_array_template, length, zero=True)
 *         count_t = array.clone(int_array_template, length, zero=True)
 */
  __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1001; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_count_c = ((arrayobject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":1002
 *         count_a = array.clone(int_array_template, length, zero=True)
 *         count_c = array.clone(int_array_template, length, zero=True)
 *         count_g = array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 *         count_t = array.clone(int_array_template, length, zero=True)
 * 
 */
  __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_count_g = ((arrayobject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":1003
 *         count_c = array.clone(int_array_template, length, zero=True)
 *         count_g = array.clone(int_array_template, length, zero=True)
 *         count_t = array.clone(int_array_template, length, zero=True)             # <<<<<<<<<<<<<<
 * 
 *         cdef char * seq
 */
  __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_5array_clone(__pyx_v_int_array_template, __pyx_v_length, 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1003; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_count_t = ((arrayobject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":1009
 *         cdef int qpos
 *         cdef int refpos
 *         cdef int c = 0             # <<<<<<<<<<<<<<
 *         cdef int _threshold = quality_threshold
 *         for read in self.fetch(chr, start, stop):
 */
  __pyx_v_c = 0;

  /* "pysam/calignmentfile.pyx":1010
 *         cdef int refpos
 *         cdef int c = 0
 *         cdef int _threshold = quality_threshold             # <<<<<<<<<<<<<<
 *         for read in self.fetch(chr, start, stop):
 *             if read_callback == 'all':
 */
  __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_quality_threshold); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v__threshold = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":1011
 *         cdef int c = 0
 *         cdef int _threshold = quality_threshold
 *         for read in self.fetch(chr, start, stop):             # <<<<<<<<<<<<<<
 *             if read_callback == 'all':
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_fetch); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && 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_5 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(3+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_4) {
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
  }
  __Pyx_INCREF(__pyx_v_chr);
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_chr);
  __Pyx_GIVEREF(__pyx_v_chr);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_stop);
  PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_stop);
  __Pyx_GIVEREF(__pyx_v_stop);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_3);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XDECREF_SET(__pyx_v_read, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "pysam/calignmentfile.pyx":1012
 *         cdef int _threshold = quality_threshold
 *         for read in self.fetch(chr, start, stop):
 *             if read_callback == 'all':             # <<<<<<<<<<<<<<
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 *                     continue
 */
    __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_8) {

      /* "pysam/calignmentfile.pyx":1013
 *         for read in self.fetch(chr, start, stop):
 *             if read_callback == 'all':
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):             # <<<<<<<<<<<<<<
 *                     continue
 *             elif read_callback == 'nofilter':
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_read, __pyx_n_s_flag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = PyNumber_And(__pyx_t_2, __pyx_int_1796); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1013; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_8) {

        /* "pysam/calignmentfile.pyx":1014
 *             if read_callback == 'all':
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 *                     continue             # <<<<<<<<<<<<<<
 *             elif read_callback == 'nofilter':
 *                 pass
 */
        goto __pyx_L3_continue;
      }
      goto __pyx_L5;
    }

    /* "pysam/calignmentfile.pyx":1015
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 *                     continue
 *             elif read_callback == 'nofilter':             # <<<<<<<<<<<<<<
 *                 pass
 *             else:
 */
    __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_read_callback, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_8) {
      goto __pyx_L5;
    }
    /*else*/ {

      /* "pysam/calignmentfile.pyx":1018
 *                 pass
 *             else:
 *                 if not read_callback(read):             # <<<<<<<<<<<<<<
 *                     continue
 *             seq = read.seq
 */
      __Pyx_INCREF(__pyx_v_read_callback);
      __pyx_t_2 = __pyx_v_read_callback; __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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);
        }
      }
      if (!__pyx_t_4) {
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_read); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
      } else {
        __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
        __Pyx_INCREF(__pyx_v_read);
        PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_read);
        __Pyx_GIVEREF(__pyx_v_read);
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1018; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_10 = ((!__pyx_t_8) != 0);
      if (__pyx_t_10) {

        /* "pysam/calignmentfile.pyx":1019
 *             else:
 *                 if not read_callback(read):
 *                     continue             # <<<<<<<<<<<<<<
 *             seq = read.seq
 *             quality = read.query_qualities
 */
        goto __pyx_L3_continue;
      }
    }
    __pyx_L5:;

    /* "pysam/calignmentfile.pyx":1020
 *                 if not read_callback(read):
 *                     continue
 *             seq = read.seq             # <<<<<<<<<<<<<<
 *             quality = read.query_qualities
 *             for qpos, refpos in read.get_aligned_pairs(True):
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_read, __pyx_n_s_seq); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_11 = __Pyx_PyObject_AsString(__pyx_t_6); if (unlikely((!__pyx_t_11) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_seq = __pyx_t_11;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "pysam/calignmentfile.pyx":1021
 *                     continue
 *             seq = read.seq
 *             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_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_read, __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_7cpython_5array_array))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1021; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF_SET(__pyx_v_quality, ((arrayobject *)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "pysam/calignmentfile.pyx":1022
 *             seq = read.seq
 *             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:
 *                     if quality[qpos] > quality_threshold:
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_read, __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_6 = __pyx_t_2; __Pyx_INCREF(__pyx_t_6); __pyx_t_12 = 0;
      __pyx_t_13 = NULL;
    } else {
      __pyx_t_12 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_13 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (likely(!__pyx_t_13)) {
        if (likely(PyList_CheckExact(__pyx_t_6))) {
          if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_6)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_12); __Pyx_INCREF(__pyx_t_2); __pyx_t_12++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_6, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_12 >= PyTuple_GET_SIZE(__pyx_t_6)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_12); __Pyx_INCREF(__pyx_t_2); __pyx_t_12++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_6, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_13(__pyx_t_6);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
        PyObject* sequence = __pyx_t_2;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_9 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_4);
        #else
        __pyx_t_9 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        #endif
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_14 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
        index = 0; __pyx_t_9 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_9)) goto __pyx_L10_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_9);
        index = 1; __pyx_t_4 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_4)) goto __pyx_L10_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_4);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_15 = NULL;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        goto __pyx_L11_unpacking_done;
        __pyx_L10_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_15 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L11_unpacking_done:;
      }
      __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_16 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_v_qpos = __pyx_t_1;
      __pyx_v_refpos = __pyx_t_16;

      /* "pysam/calignmentfile.pyx":1023
 *             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:             # <<<<<<<<<<<<<<
 *                     if quality[qpos] > quality_threshold:
 *                         if seq[qpos] == 'A':
 */
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_qpos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = (__pyx_t_2 != Py_None);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_17 = (__pyx_t_8 != 0);
      if (__pyx_t_17) {
      } else {
        __pyx_t_10 = __pyx_t_17;
        goto __pyx_L13_bool_binop_done;
      }
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_refpos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_17 = (__pyx_t_2 != Py_None);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_8 = (__pyx_t_17 != 0);
      if (__pyx_t_8) {
      } else {
        __pyx_t_10 = __pyx_t_8;
        goto __pyx_L13_bool_binop_done;
      }
      __pyx_t_8 = (__pyx_v__start <= __pyx_v_refpos);
      if (__pyx_t_8) {
        __pyx_t_8 = (__pyx_v_refpos < __pyx_v__stop);
      }
      __pyx_t_17 = (__pyx_t_8 != 0);
      __pyx_t_10 = __pyx_t_17;
      __pyx_L13_bool_binop_done:;
      if (__pyx_t_10) {

        /* "pysam/calignmentfile.pyx":1024
 *             for qpos, refpos in read.get_aligned_pairs(True):
 *                 if qpos is not None and refpos is not None and _start <= refpos < _stop:
 *                     if quality[qpos] > quality_threshold:             # <<<<<<<<<<<<<<
 *                         if seq[qpos] == 'A':
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 */
        __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_quality), __pyx_v_qpos, int, 1, __Pyx_PyInt_From_int, 0, 1, 0); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_v_quality_threshold, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (__pyx_t_10) {

          /* "pysam/calignmentfile.pyx":1025
 *                 if qpos is not None and refpos is not None and _start <= refpos < _stop:
 *                     if quality[qpos] > quality_threshold:
 *                         if seq[qpos] == 'A':             # <<<<<<<<<<<<<<
 *                             count_a.data.as_ulongs[refpos - _start] += 1
 *                         if seq[qpos] == 'C':
 */
          __pyx_t_10 = (((__pyx_v_seq[__pyx_v_qpos]) == 'A') != 0);
          if (__pyx_t_10) {

            /* "pysam/calignmentfile.pyx":1026
 *                     if quality[qpos] > quality_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_16 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_a->data.as_ulongs[__pyx_t_16]) = ((__pyx_v_count_a->data.as_ulongs[__pyx_t_16]) + 1);
            goto __pyx_L17;
          }
          __pyx_L17:;

          /* "pysam/calignmentfile.pyx":1027
 *                         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_v_seq[__pyx_v_qpos]) == 'C') != 0);
          if (__pyx_t_10) {

            /* "pysam/calignmentfile.pyx":1028
 *                             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_16 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_c->data.as_ulongs[__pyx_t_16]) = ((__pyx_v_count_c->data.as_ulongs[__pyx_t_16]) + 1);
            goto __pyx_L18;
          }
          __pyx_L18:;

          /* "pysam/calignmentfile.pyx":1029
 *                         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_v_seq[__pyx_v_qpos]) == 'G') != 0);
          if (__pyx_t_10) {

            /* "pysam/calignmentfile.pyx":1030
 *                             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_16 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_g->data.as_ulongs[__pyx_t_16]) = ((__pyx_v_count_g->data.as_ulongs[__pyx_t_16]) + 1);
            goto __pyx_L19;
          }
          __pyx_L19:;

          /* "pysam/calignmentfile.pyx":1031
 *                         if seq[qpos] == 'G':
 *                             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_10 = (((__pyx_v_seq[__pyx_v_qpos]) == 'T') != 0);
          if (__pyx_t_10) {

            /* "pysam/calignmentfile.pyx":1032
 *                             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_16 = (__pyx_v_refpos - __pyx_v__start);
            (__pyx_v_count_t->data.as_ulongs[__pyx_t_16]) = ((__pyx_v_count_t->data.as_ulongs[__pyx_t_16]) + 1);
            goto __pyx_L20;
          }
          __pyx_L20:;
          goto __pyx_L16;
        }
        __pyx_L16:;
        goto __pyx_L12;
      }
      __pyx_L12:;

      /* "pysam/calignmentfile.pyx":1022
 *             seq = read.seq
 *             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:
 *                     if quality[qpos] > quality_threshold:
 */
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "pysam/calignmentfile.pyx":1011
 *         cdef int c = 0
 *         cdef int _threshold = quality_threshold
 *         for read in self.fetch(chr, start, stop):             # <<<<<<<<<<<<<<
 *             if read_callback == 'all':
 *                 if (read.flag & (0x4 | 0x100 | 0x200 | 0x400)):
 */
    __pyx_L3_continue:;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/calignmentfile.pyx":1033
 *                         if seq[qpos] == 'T':
 *                             count_t.data.as_ulongs[refpos - _start] += 1
 *         return count_a, count_c, count_g, count_t             # <<<<<<<<<<<<<<
 * 
 *     def close(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_v_count_a));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_count_a));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_count_a));
  __Pyx_INCREF(((PyObject *)__pyx_v_count_c));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_count_c));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_count_c));
  __Pyx_INCREF(((PyObject *)__pyx_v_count_g));
  PyTuple_SET_ITEM(__pyx_t_3, 2, ((PyObject *)__pyx_v_count_g));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_count_g));
  __Pyx_INCREF(((PyObject *)__pyx_v_count_t));
  PyTuple_SET_ITEM(__pyx_t_3, 3, ((PyObject *)__pyx_v_count_t));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_count_t));
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":968
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking
 *     def count_coverage(self, chr, start, stop, quality_threshold = 15,             # <<<<<<<<<<<<<<
 *                        read_callback = 'all'):
 *         """Count ACGT in a part of a AlignmentFile.
 */

  /* 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_6);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_AddTraceback("pysam.calignmentfile.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_quality);
  __Pyx_XDECREF(__pyx_v_read);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1035
 *         return count_a, count_c, count_g, count_t
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         '''
 *         closes the :class:`pysam.AlignmentFile`.'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_33close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_32close[] = "AlignmentFile.close(self)\n\n        closes the :class:`pysam.AlignmentFile`.";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_33close(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_32close(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

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

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

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

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

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

  /* "pysam/calignmentfile.pyx":1035
 *         return count_a, count_c, count_g, count_t
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         '''
 *         closes the :class:`pysam.AlignmentFile`.'''
 */

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

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

/* Python wrapper */
static void __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_35__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_35__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_34__dealloc__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static void __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_34__dealloc__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  __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_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1043);

  /* "pysam/calignmentfile.pyx":1053
 *         # been working for years.
 * 
 *         self.close()             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         if self.header != NULL:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_close); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1054
 * 
 *         self.close()
 *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
 *         if self.header != NULL:
 *             bam_hdr_destroy(self.header)
 */
  bam_destroy1(__pyx_v_self->b);

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

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

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

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

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

static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_37write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
static int __pyx_f_5pysam_14calignmentfile_13AlignmentFile_write(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_read, int __pyx_skip_dispatch) {
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("write", 0);
  __Pyx_TraceCall("write", __pyx_f[0], 1058);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_write); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_37write)) {
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && 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);
        }
      }
      if (!__pyx_t_4) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)__pyx_v_read)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
        __Pyx_INCREF(((PyObject *)__pyx_v_read));
        PyTuple_SET_ITEM(__pyx_t_5, 0+1, ((PyObject *)__pyx_v_read));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_read));
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_r = __pyx_t_6;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/calignmentfile.pyx":1064
 *         returns the number of bytes written.
 *         '''
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_8 = ((!__pyx_t_7) != 0);
  if (__pyx_t_8) {

    /* "pysam/calignmentfile.pyx":1065
 *         '''
 *         if not self._isOpen():
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         cdef int ret = sam_write1(self.htsfile,
 */
    __pyx_r = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":1067
 *             return 0
 * 
 *         cdef int ret = sam_write1(self.htsfile,             # <<<<<<<<<<<<<<
 *                                   self.header,
 *                                   read._delegate)
 */
  __pyx_v_ret = sam_write1(__pyx_v_self->htsfile, __pyx_v_self->header, __pyx_v_read->_delegate);

  /* "pysam/calignmentfile.pyx":1074
 *         #      when ret == -1 we get a "SystemError: error return without
 *         #      exception set".
 *         if ret < 0:             # <<<<<<<<<<<<<<
 *             raise ValueError('sam write failed')
 * 
 */
  __pyx_t_8 = ((__pyx_v_ret < 0) != 0);
  if (__pyx_t_8) {

    /* "pysam/calignmentfile.pyx":1075
 *         #      exception set".
 *         if ret < 0:
 *             raise ValueError('sam write failed')             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1077
 *             raise ValueError('sam write failed')
 * 
 *         return ret             # <<<<<<<<<<<<<<
 * 
 *     def __enter__(self):
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1058
 *             bam_hdr_destroy(self.header)
 * 
 *     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_5);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_37write(PyObject *__pyx_v_self, PyObject *__pyx_v_read); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_36write[] = "AlignmentFile.write(self, AlignedSegment read) -> int\n\n        write a single :class:`pysam.AlignedSegment` to disk.\n\n        returns the number of bytes written.\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_37write(PyObject *__pyx_v_self, PyObject *__pyx_v_read) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_read), __pyx_ptype_5pysam_14calignmentfile_AlignedSegment, 1, "read", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_36write(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), ((struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_13AlignmentFile_36write(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_read) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("write", 0);
  __Pyx_TraceCall("write", __pyx_f[0], 1058);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile_13AlignmentFile_write(__pyx_v_self, __pyx_v_read, 1); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __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.calignmentfile.AlignmentFile.write", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1079
 *         return ret
 * 
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_39__enter__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_38__enter__[] = "AlignmentFile.__enter__(self)";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_39__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_14calignmentfile_13AlignmentFile_38__enter__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_38__enter__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__enter__", 0);
  __Pyx_TraceCall("__enter__", __pyx_f[0], 1079);

  /* "pysam/calignmentfile.pyx":1080
 * 
 *     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/calignmentfile.pyx":1079
 *         return ret
 * 
 *     def __enter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

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

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

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_41__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_40__exit__[] = "AlignmentFile.__exit__(self, exc_type, exc_value, traceback)";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_41__exit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_exc_type = 0;
  CYTHON_UNUSED PyObject *__pyx_v_exc_value = 0;
  CYTHON_UNUSED PyObject *__pyx_v_traceback = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__exit__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_exc_type,&__pyx_n_s_exc_value,&__pyx_n_s_traceback,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_exc_type)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_exc_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_traceback)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__exit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_exc_type = values[0];
    __pyx_v_exc_value = values[1];
    __pyx_v_traceback = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__exit__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_40__exit__(((struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_13AlignmentFile_40__exit__(struct __pyx_obj_5pysam_14calignmentfile_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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__exit__", 0);
  __Pyx_TraceCall("__exit__", __pyx_f[0], 1082);

  /* "pysam/calignmentfile.pyx":1083
 * 
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1084
 *     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/calignmentfile.pyx":1082
 *         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.calignmentfile.AlignmentFile.__exit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1093
 *     property filename:
 *         '''filename associated with this object.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._filename
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_8filename_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_8filename_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_8filename___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_8filename___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1093);

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

  /* "pysam/calignmentfile.pyx":1093
 *     property filename:
 *         '''filename associated with this object.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._filename
 * 
 */

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

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

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_11nreferences_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_11nreferences_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_11nreferences___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":1099
 *         '''number of :term:`reference` sequences in the file.'''
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             return self.header.n_targets
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

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

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

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

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_10references_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_10references_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_10references___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_10references___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_v_t = NULL;
  long __pyx_v_x;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int32_t __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1104);

  /* "pysam/calignmentfile.pyx":1105
 *         """tuple with the names of :term:`reference` sequences."""
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             t = []
 *             for x from 0 <= x < self.header.n_targets:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

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

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

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

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

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

/* "pysam/calignmentfile.pyx":1117
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen():
 *                 raise ValueError("I/O operation on closed file")
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_7lengths_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_7lengths_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_7lengths___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_7lengths___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_v_t = NULL;
  long __pyx_v_x;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int32_t __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1117);

  /* "pysam/calignmentfile.pyx":1118
 *         """
 *         def __get__(self):
 *             if not self._isOpen():             # <<<<<<<<<<<<<<
 *                 raise ValueError("I/O operation on closed file")
 *             t = []
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":1119
 *         def __get__(self):
 *             if not self._isOpen():
 *                 raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *             t = []
 *             for x from 0 <= x < self.header.n_targets:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

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

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

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

  /* "pysam/calignmentfile.pyx":1117
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen():
 *                 raise ValueError("I/O operation on closed file")
 */

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

/* "pysam/calignmentfile.pyx":1129
 *         to the statistics recorded in the index.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             cdef int tid
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_6mapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_6mapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6mapped___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6mapped___get__(struct __pyx_obj_5pysam_14calignmentfile_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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int32_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1129);

  /* "pysam/calignmentfile.pyx":1130
 *         """
 *         def __get__(self):
 *             self._checkIndex()             # <<<<<<<<<<<<<<
 *             cdef int tid
 *             cdef uint64_t total = 0
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_checkIndex); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

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

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

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

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

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

  /* "pysam/calignmentfile.pyx":1129
 *         to the statistics recorded in the index.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             cdef int tid
 */

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

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

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_43_checkIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_42_checkIndex[] = "AlignmentFile._checkIndex(self)\ncheck if index is present. Otherwise raise\n        an error.";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_43_checkIndex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_checkIndex (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_42_checkIndex(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":1142
 *         '''check if index is present. Otherwise raise
 *         an error.'''
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam and not self.is_cram:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":1143
 *         an error.'''
 *         if not self._isOpen():
 *             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__36, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1144
 *         if not self._isOpen():
 *             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_4 = ((!(__pyx_v_self->is_bam != 0)) != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_5 = __pyx_t_4;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_4 = ((!(__pyx_v_self->is_cram != 0)) != 0);
  __pyx_t_5 = __pyx_t_4;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":1145
 *             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__37, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

    /* "pysam/calignmentfile.pyx":1148
 *                 "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__38, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

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

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile._checkIndex", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1157
 *         to the statistics recorded in the index.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             cdef int tid
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_8unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_8unmapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_8unmapped___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_8unmapped___get__(struct __pyx_obj_5pysam_14calignmentfile_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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int32_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1157);

  /* "pysam/calignmentfile.pyx":1158
 *         """
 *         def __get__(self):
 *             self._checkIndex()             # <<<<<<<<<<<<<<
 *             cdef int tid
 *             cdef uint64_t total = 0
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_checkIndex); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

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

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

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

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

  /* "pysam/calignmentfile.pyx":1165
 *                 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_filename = __pyx_f[0]; __pyx_lineno = 1165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1157
 *         to the statistics recorded in the index.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             cdef int tid
 */

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

/* "pysam/calignmentfile.pyx":1171
 *         to the statistics recorded in the index.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             return hts_idx_get_n_no_coor(self.index)
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_12nocoordinate_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_12nocoordinate_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_12nocoordinate___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":1172
 *         """
 *         def __get__(self):
 *             self._checkIndex()             # <<<<<<<<<<<<<<
 *             return hts_idx_get_n_no_coor(self.index)
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_checkIndex); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1173
 *         def __get__(self):
 *             self._checkIndex()
 *             return hts_idx_get_n_no_coor(self.index)             # <<<<<<<<<<<<<<
 * 
 *     property text:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint64_t(hts_idx_get_n_no_coor(__pyx_v_self->index)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1173; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1171
 *         to the statistics recorded in the index.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             self._checkIndex()
 *             return hts_idx_get_n_no_coor(self.index)
 */

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

/* "pysam/calignmentfile.pyx":1182
 * 
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen():
 *                 raise ValueError( "I/O operation on closed file" )
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_4text_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_4text_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_4text___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":1183
 *         '''
 *         def __get__(self):
 *             if not self._isOpen():             # <<<<<<<<<<<<<<
 *                 raise ValueError( "I/O operation on closed file" )
 *             return from_string_and_size(self.header.text, self.header.l_text)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":1184
 *         def __get__(self):
 *             if not self._isOpen():
 *                 raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             return from_string_and_size(self.header.text, self.header.l_text)
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1185
 *             if not self._isOpen():
 *                 raise ValueError( "I/O operation on closed file" )
 *             return from_string_and_size(self.header.text, self.header.l_text)             # <<<<<<<<<<<<<<
 * 
 *     property header:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile_from_string_and_size(__pyx_v_self->header->text, __pyx_v_self->header->l_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1185; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1182
 * 
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen():
 *                 raise ValueError( "I/O operation on closed file" )
 */

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

/* "pysam/calignmentfile.pyx":1208
 * 
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen():
 *                 raise ValueError( "I/O operation on closed file" )
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_6header_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_6header_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6header___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6header___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__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_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  Py_ssize_t __pyx_t_10;
  PyObject *(*__pyx_t_11)(PyObject *);
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *(*__pyx_t_15)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1208);

  /* "pysam/calignmentfile.pyx":1209
 *         '''
 *         def __get__(self):
 *             if not self._isOpen():             # <<<<<<<<<<<<<<
 *                 raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":1210
 *         def __get__(self):
 *             if not self._isOpen():
 *                 raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *             result = {}
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1212
 *                 raise ValueError( "I/O operation on closed file" )
 * 
 *             result = {}             # <<<<<<<<<<<<<<
 * 
 *             if self.header.text != NULL:
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_result = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1214
 *             result = {}
 * 
 *             if self.header.text != NULL:             # <<<<<<<<<<<<<<
 *                 # convert to python string (note: call self.text to
 *                 # create 0-terminated string)
 */
  __pyx_t_5 = ((__pyx_v_self->header->text != NULL) != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":1217
 *                 # convert to python string (note: call self.text to
 *                 # create 0-terminated string)
 *                 t = self.text             # <<<<<<<<<<<<<<
 *                 for line in t.split("\n"):
 *                     if not line.strip(): continue
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_text); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_t = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "pysam/calignmentfile.pyx":1218
 *                 # create 0-terminated string)
 *                 t = self.text
 *                 for line in t.split("\n"):             # <<<<<<<<<<<<<<
 *                     if not line.strip(): continue
 *                     assert line.startswith("@"), \
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_split); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __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_6 = 0;
      __pyx_t_7 = NULL;
    } else {
      __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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_COMPILING_IN_CPYTHON
          __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_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __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_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #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(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/calignmentfile.pyx":1219
 *                 t = self.text
 *                 for line in t.split("\n"):
 *                     if not line.strip(): continue             # <<<<<<<<<<<<<<
 *                     assert line.startswith("@"), \
 *                         "header line without '@': '%s'" % line
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_line, __pyx_n_s_strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      if (__pyx_t_8) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else {
        __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_4 = ((!__pyx_t_5) != 0);
      if (__pyx_t_4) {
        goto __pyx_L5_continue;
      }

      /* "pysam/calignmentfile.pyx":1220
 *                 for line in t.split("\n"):
 *                     if not line.strip(): 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_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_4)) {

          /* "pysam/calignmentfile.pyx":1221
 *                     if not line.strip(): continue
 *                     assert line.startswith("@"), \
 *                         "header line without '@': '%s'" % line             # <<<<<<<<<<<<<<
 *                     fields = line[1:].split("\t")
 *                     record = fields[0]
 */
          __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_header_line_without_s, __pyx_v_line); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1221; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          PyErr_SetObject(PyExc_AssertionError, __pyx_t_3);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
      }
      #endif

      /* "pysam/calignmentfile.pyx":1222
 *                     assert line.startswith("@"), \
 *                         "header line without '@': '%s'" % line
 *                     fields = line[1:].split("\t")             # <<<<<<<<<<<<<<
 *                     record = fields[0]
 *                     assert record in VALID_HEADER_TYPES, \
 */
      __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_v_line, 1, 0, NULL, NULL, &__pyx_slice__45, 1, 0, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__47, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignmentfile.pyx":1223
 *                         "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_3 = __Pyx_GetItemInt(__pyx_v_fields, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1223; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignmentfile.pyx":1224
 *                     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_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_t_3, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!(__pyx_t_4 != 0))) {

          /* "pysam/calignmentfile.pyx":1225
 *                     record = fields[0]
 *                     assert record in VALID_HEADER_TYPES, \
 *                         "header line with invalid type '%s': '%s'" % (record, line)             # <<<<<<<<<<<<<<
 * 
 *                     # treat comments
 */
          __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_INCREF(__pyx_v_record);
          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_record);
          __Pyx_GIVEREF(__pyx_v_record);
          __Pyx_INCREF(__pyx_v_line);
          PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_line);
          __Pyx_GIVEREF(__pyx_v_line);
          __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_header_line_with_invalid_type_s, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1225; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          PyErr_SetObject(PyExc_AssertionError, __pyx_t_2);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
      }
      #endif

      /* "pysam/calignmentfile.pyx":1228
 * 
 *                     # treat comments
 *                     if record == "CO":             # <<<<<<<<<<<<<<
 *                         if record not in result:
 *                             result[record] = []
 */
      __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_v_record, __pyx_n_s_CO, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_4) {

        /* "pysam/calignmentfile.pyx":1229
 *                     # treat comments
 *                     if record == "CO":
 *                         if record not in result:             # <<<<<<<<<<<<<<
 *                             result[record] = []
 *                         result[record].append("\t".join( fields[1:]))
 */
        __pyx_t_4 = (__Pyx_PyDict_Contains(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_5 = (__pyx_t_4 != 0);
        if (__pyx_t_5) {

          /* "pysam/calignmentfile.pyx":1230
 *                     if record == "CO":
 *                         if record not in result:
 *                             result[record] = []             # <<<<<<<<<<<<<<
 *                         result[record].append("\t".join( fields[1:]))
 *                         continue
 */
          __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_2) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1230; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          goto __pyx_L9;
        }
        __pyx_L9:;

        /* "pysam/calignmentfile.pyx":1231
 *                         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_2 = __Pyx_PyDict_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1231; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__48, 1, 0, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_8 = __Pyx_PyString_Join(__pyx_kp_s__46, __pyx_t_3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_2, __pyx_t_8); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

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

      /* "pysam/calignmentfile.pyx":1234
 *                         continue
 *                     # the following is clumsy as generators do not work?
 *                     x = {}             # <<<<<<<<<<<<<<
 * 
 *                     for idx, field in enumerate(fields[1:]):
 */
      __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_XDECREF_SET(__pyx_v_x, ((PyObject*)__pyx_t_8));
      __pyx_t_8 = 0;

      /* "pysam/calignmentfile.pyx":1236
 *                     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_8 = __pyx_int_0;
      __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_fields, 1, 0, NULL, NULL, &__pyx_slice__49, 1, 0, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
        __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_10 = 0;
        __pyx_t_11 = NULL;
      } else {
        __pyx_t_10 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_11 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      for (;;) {
        if (likely(!__pyx_t_11)) {
          if (likely(PyList_CheckExact(__pyx_t_3))) {
            if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_10); __Pyx_INCREF(__pyx_t_2); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #endif
          } else {
            if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_10); __Pyx_INCREF(__pyx_t_2); __pyx_t_10++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #endif
          }
        } else {
          __pyx_t_2 = __pyx_t_11(__pyx_t_3);
          if (unlikely(!__pyx_t_2)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_2);
        }
        __Pyx_XDECREF_SET(__pyx_v_field, __pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_8);
        __pyx_t_2 = PyNumber_Add(__pyx_t_8, __pyx_int_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8);
        __pyx_t_8 = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "pysam/calignmentfile.pyx":1237
 * 
 *                     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_5 = (__Pyx_PySequence_Contains(__pyx_kp_s__50, __pyx_v_field, Py_NE)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_4 = (__pyx_t_5 != 0);
        if (__pyx_t_4) {

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

        /* "pysam/calignmentfile.pyx":1239
 *                         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_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_field, __pyx_n_s_split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__52, NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) {
          PyObject* sequence = __pyx_t_12;
          #if CYTHON_COMPILING_IN_CPYTHON
          Py_ssize_t size = Py_SIZE(sequence);
          #else
          Py_ssize_t size = PySequence_Size(sequence);
          #endif
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          #if CYTHON_COMPILING_IN_CPYTHON
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_13 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_13 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_13);
          #else
          __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_13 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __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_2 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_2)) goto __pyx_L13_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_2);
          index = 1; __pyx_t_13 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_13)) goto __pyx_L13_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_13);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_15 = NULL;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          goto __pyx_L14_unpacking_done;
          __pyx_L13_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __pyx_t_15 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_L14_unpacking_done:;
        }
        __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_13);
        __pyx_t_13 = 0;

        /* "pysam/calignmentfile.pyx":1240
 *                             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_4 = (__Pyx_PyString_Equals(__pyx_t_12, __pyx_n_s_CL, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_5 = (__pyx_t_4 != 0);
        if (__pyx_t_5) {

          /* "pysam/calignmentfile.pyx":1247
 *                             # 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] = VALID_HEADER_FIELDS[record][key](value)
 *                             break
 */
          __pyx_t_12 = PyNumber_Add(__pyx_v_idx, __pyx_int_1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __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__46, __pyx_t_13); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __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__53, NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __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;
            #if CYTHON_COMPILING_IN_CPYTHON
            Py_ssize_t size = Py_SIZE(sequence);
            #else
            Py_ssize_t size = PySequence_Size(sequence);
            #endif
            if (unlikely(size != 2)) {
              if (size > 2) __Pyx_RaiseTooManyValuesError(2);
              else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
              {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            #if CYTHON_COMPILING_IN_CPYTHON
            if (likely(PyTuple_CheckExact(sequence))) {
              __pyx_t_13 = PyTuple_GET_ITEM(sequence, 0); 
              __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
            } else {
              __pyx_t_13 = PyList_GET_ITEM(sequence, 0); 
              __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
            }
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(__pyx_t_2);
            #else
            __pyx_t_13 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_13);
            __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_2);
            #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_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __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_L16_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_13);
            index = 1; __pyx_t_2 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_2)) goto __pyx_L16_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_2);
            if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __pyx_t_15 = NULL;
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
            goto __pyx_L17_unpacking_done;
            __pyx_L16_unpacking_failed:;
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
            __pyx_t_15 = NULL;
            if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __pyx_L17_unpacking_done:;
          }
          __Pyx_DECREF_SET(__pyx_v_key, __pyx_t_13);
          __pyx_t_13 = 0;
          __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_2);
          __pyx_t_2 = 0;

          /* "pysam/calignmentfile.pyx":1248
 *                             # SAM API, consume the rest of the line.
 *                             key, value = "\t".join(fields[idx+1:]).split(":", 1)
 *                             x[key] = VALID_HEADER_FIELDS[record][key](value)             # <<<<<<<<<<<<<<
 *                             break
 * 
 */
          __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_13 = PyObject_GetItem(__pyx_t_2, __pyx_v_record); if (unlikely(__pyx_t_13 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_2 = PyObject_GetItem(__pyx_t_13, __pyx_v_key); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_13 = NULL;
          if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_2);
            if (likely(__pyx_t_13)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
              __Pyx_INCREF(__pyx_t_13);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_2, function);
            }
          }
          if (!__pyx_t_13) {
            __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_value); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_12);
          } else {
            __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_14);
            PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_13); __Pyx_GIVEREF(__pyx_t_13); __pyx_t_13 = NULL;
            __Pyx_INCREF(__pyx_v_value);
            PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_v_value);
            __Pyx_GIVEREF(__pyx_v_value);
            __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_14, NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_12);
            __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          }
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_t_12) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

          /* "pysam/calignmentfile.pyx":1249
 *                             key, value = "\t".join(fields[idx+1:]).split(":", 1)
 *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
 *                             break             # <<<<<<<<<<<<<<
 * 
 *                         # uppercase keys must be valid
 */
          goto __pyx_L11_break;
        }

        /* "pysam/calignmentfile.pyx":1252
 * 
 *                         # uppercase keys must be valid
 *                         if key in VALID_HEADER_FIELDS[record]:             # <<<<<<<<<<<<<<
 *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
 *                         # lowercase are permitted for user fields
 */
        __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_2 = PyObject_GetItem(__pyx_t_12, __pyx_v_record); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1252; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_5 = (__Pyx_PySequence_Contains(__pyx_v_key, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_4 = (__pyx_t_5 != 0);
        if (__pyx_t_4) {

          /* "pysam/calignmentfile.pyx":1253
 *                         # uppercase keys must be valid
 *                         if key in VALID_HEADER_FIELDS[record]:
 *                             x[key] = VALID_HEADER_FIELDS[record][key](value)             # <<<<<<<<<<<<<<
 *                         # lowercase are permitted for user fields
 *                         elif not key.isupper():
 */
          __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_FIELDS); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_12);
          __pyx_t_14 = PyObject_GetItem(__pyx_t_12, __pyx_v_record); if (unlikely(__pyx_t_14 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1253; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          __pyx_t_12 = PyObject_GetItem(__pyx_t_14, __pyx_v_key); if (unlikely(__pyx_t_12 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1253; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __pyx_t_14 = NULL;
          if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_12))) {
            __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_12);
            if (likely(__pyx_t_14)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
              __Pyx_INCREF(__pyx_t_14);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_12, function);
            }
          }
          if (!__pyx_t_14) {
            __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_v_value); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_2);
          } else {
            __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_13);
            PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_14); __Pyx_GIVEREF(__pyx_t_14); __pyx_t_14 = NULL;
            __Pyx_INCREF(__pyx_v_value);
            PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_v_value);
            __Pyx_GIVEREF(__pyx_v_value);
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_13, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          }
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          if (unlikely(PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_t_2) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          goto __pyx_L18;
        }

        /* "pysam/calignmentfile.pyx":1255
 *                             x[key] = VALID_HEADER_FIELDS[record][key](value)
 *                         # lowercase are permitted for user fields
 *                         elif not key.isupper():             # <<<<<<<<<<<<<<
 *                             x[key] = value
 *                         else:
 */
        __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_key, __pyx_n_s_isupper); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_13 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_12))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_12, function);
          }
        }
        if (__pyx_t_13) {
          __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_13); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        } else {
          __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_12); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_5 = ((!__pyx_t_4) != 0);
        if (__pyx_t_5) {

          /* "pysam/calignmentfile.pyx":1256
 *                         # lowercase are permitted for user fields
 *                         elif not key.isupper():
 *                             x[key] = value             # <<<<<<<<<<<<<<
 *                         else:
 *                             raise ValueError(
 */
          if (unlikely(PyDict_SetItem(__pyx_v_x, __pyx_v_key, __pyx_v_value) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          goto __pyx_L18;
        }
        /*else*/ {

          /* "pysam/calignmentfile.pyx":1260
 *                             raise ValueError(
 *                                 "unknown field code '%s' in record '%s'" %
 *                                 (key, record))             # <<<<<<<<<<<<<<
 * 
 *                     if VALID_HEADER_TYPES[record] == dict:
 */
          __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1260; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_INCREF(__pyx_v_key);
          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_key);
          __Pyx_GIVEREF(__pyx_v_key);
          __Pyx_INCREF(__pyx_v_record);
          PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_record);
          __Pyx_GIVEREF(__pyx_v_record);

          /* "pysam/calignmentfile.pyx":1259
 *                         else:
 *                             raise ValueError(
 *                                 "unknown field code '%s' in record '%s'" %             # <<<<<<<<<<<<<<
 *                                 (key, record))
 * 
 */
          __pyx_t_12 = __Pyx_PyString_Format(__pyx_kp_s_unknown_field_code_s_in_record_s, __pyx_t_2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

          /* "pysam/calignmentfile.pyx":1258
 *                             x[key] = value
 *                         else:
 *                             raise ValueError(             # <<<<<<<<<<<<<<
 *                                 "unknown field code '%s' in record '%s'" %
 *                                 (key, record))
 */
          __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_12);
          __Pyx_GIVEREF(__pyx_t_12);
          __pyx_t_12 = 0;
          __pyx_t_12 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_Raise(__pyx_t_12, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __pyx_L18:;

        /* "pysam/calignmentfile.pyx":1236
 *                     x = {}
 * 
 *                     for idx, field in enumerate(fields[1:]):             # <<<<<<<<<<<<<<
 *                         if ":" not in field:
 *                             raise ValueError("malformatted header: no ':' in field" )
 */
      }
      __pyx_L11_break:;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "pysam/calignmentfile.pyx":1262
 *                                 (key, record))
 * 
 *                     if VALID_HEADER_TYPES[record] == dict:             # <<<<<<<<<<<<<<
 *                         if record in result:
 *                             raise ValueError(
 */
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1262; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyObject_RichCompare(__pyx_t_3, ((PyObject *)((PyObject*)(&PyDict_Type))), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_5) {

        /* "pysam/calignmentfile.pyx":1263
 * 
 *                     if VALID_HEADER_TYPES[record] == dict:
 *                         if record in result:             # <<<<<<<<<<<<<<
 *                             raise ValueError(
 *                                 "multiple '%s' lines are not permitted" % record)
 */
        __pyx_t_5 = (__Pyx_PyDict_Contains(__pyx_v_record, __pyx_v_result, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_4 = (__pyx_t_5 != 0);
        if (__pyx_t_4) {

          /* "pysam/calignmentfile.pyx":1265
 *                         if record in result:
 *                             raise ValueError(
 *                                 "multiple '%s' lines are not permitted" % record)             # <<<<<<<<<<<<<<
 * 
 *                         result[record] = x
 */
          __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_multiple_s_lines_are_not_permitt, __pyx_v_record); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);

          /* "pysam/calignmentfile.pyx":1264
 *                     if VALID_HEADER_TYPES[record] == dict:
 *                         if record in result:
 *                             raise ValueError(             # <<<<<<<<<<<<<<
 *                                 "multiple '%s' lines are not permitted" % record)
 * 
 */
          __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
          __Pyx_GIVEREF(__pyx_t_8);
          __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_Raise(__pyx_t_8, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1264; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }

        /* "pysam/calignmentfile.pyx":1267
 *                                 "multiple '%s' lines are not permitted" % record)
 * 
 *                         result[record] = x             # <<<<<<<<<<<<<<
 *                     elif VALID_HEADER_TYPES[record] == list:
 *                         if record not in result: result[record] = []
 */
        if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_record, __pyx_v_x) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L19;
      }

      /* "pysam/calignmentfile.pyx":1268
 * 
 *                         result[record] = x
 *                     elif VALID_HEADER_TYPES[record] == list:             # <<<<<<<<<<<<<<
 *                         if record not in result: result[record] = []
 *                         result[record].append(x)
 */
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = PyObject_GetItem(__pyx_t_8, __pyx_v_record); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyObject_RichCompare(__pyx_t_3, ((PyObject *)((PyObject*)(&PyList_Type))), Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_4) {

        /* "pysam/calignmentfile.pyx":1269
 *                         result[record] = x
 *                     elif VALID_HEADER_TYPES[record] == list:
 *                         if record not in result: result[record] = []             # <<<<<<<<<<<<<<
 *                         result[record].append(x)
 * 
 */
        __pyx_t_4 = (__Pyx_PyDict_Contains(__pyx_v_record, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_5 = (__pyx_t_4 != 0);
        if (__pyx_t_5) {
          __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_8);
          if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_record, __pyx_t_8) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1269; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          goto __pyx_L21;
        }
        __pyx_L21:;

        /* "pysam/calignmentfile.pyx":1270
 *                     elif VALID_HEADER_TYPES[record] == list:
 *                         if record not in result: result[record] = []
 *                         result[record].append(x)             # <<<<<<<<<<<<<<
 * 
 *                 # if there are no SQ lines in the header, add the reference names
 */
        __pyx_t_8 = __Pyx_PyDict_GetItem(__pyx_v_result, __pyx_v_record); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_8, __pyx_v_x); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L19;
      }
      __pyx_L19:;

      /* "pysam/calignmentfile.pyx":1218
 *                 # create 0-terminated string)
 *                 t = self.text
 *                 for line in t.split("\n"):             # <<<<<<<<<<<<<<
 *                     if not line.strip(): continue
 *                     assert line.startswith("@"), \
 */
      __pyx_L5_continue:;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysam/calignmentfile.pyx":1280
 *                 # 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_5 = (__Pyx_PyDict_Contains(__pyx_n_s_SQ, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = (__pyx_t_5 != 0);
    if (__pyx_t_4) {

      /* "pysam/calignmentfile.pyx":1281
 *                 # 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_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1281; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_sq = ((PyObject*)__pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysam/calignmentfile.pyx":1282
 *                 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_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_references); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_lengths); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      __pyx_t_1 = 0;
      __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) {
        __pyx_t_3 = __pyx_t_8; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0;
        __pyx_t_7 = NULL;
      } else {
        __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_7 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      for (;;) {
        if (likely(!__pyx_t_7)) {
          if (likely(PyList_CheckExact(__pyx_t_3))) {
            if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_8 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #else
            __pyx_t_8 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #endif
          } else {
            if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_6); __Pyx_INCREF(__pyx_t_8); __pyx_t_6++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #else
            __pyx_t_8 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #endif
          }
        } else {
          __pyx_t_8 = __pyx_t_7(__pyx_t_3);
          if (unlikely(!__pyx_t_8)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __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;
          #if CYTHON_COMPILING_IN_CPYTHON
          Py_ssize_t size = Py_SIZE(sequence);
          #else
          Py_ssize_t size = PySequence_Size(sequence);
          #endif
          if (unlikely(size != 2)) {
            if (size > 2) __Pyx_RaiseTooManyValuesError(2);
            else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
            {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          #if CYTHON_COMPILING_IN_CPYTHON
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_12 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_12 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_12);
          #else
          __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_12 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_12);
          #endif
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_2 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_15 = Py_TYPE(__pyx_t_2)->tp_iternext;
          index = 0; __pyx_t_1 = __pyx_t_15(__pyx_t_2); if (unlikely(!__pyx_t_1)) goto __pyx_L25_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_1);
          index = 1; __pyx_t_12 = __pyx_t_15(__pyx_t_2); if (unlikely(!__pyx_t_12)) goto __pyx_L25_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_12);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_2), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_t_15 = NULL;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          goto __pyx_L26_unpacking_done;
          __pyx_L25_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_15 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __pyx_L26_unpacking_done:;
        }
        __Pyx_XDECREF_SET(__pyx_v_ref, __pyx_t_1);
        __pyx_t_1 = 0;
        __Pyx_XDECREF_SET(__pyx_v_length, __pyx_t_12);
        __pyx_t_12 = 0;

        /* "pysam/calignmentfile.pyx":1283
 *                     sq = []
 *                     for ref, length in zip(self.references, self.lengths):
 *                         sq.append({'LN': length, 'SN': ref })             # <<<<<<<<<<<<<<
 *                     result["SQ"] = sq
 * 
 */
        __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_LN, __pyx_v_length) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_SN, __pyx_v_ref) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_sq, __pyx_t_8); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

        /* "pysam/calignmentfile.pyx":1282
 *                 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_3); __pyx_t_3 = 0;

      /* "pysam/calignmentfile.pyx":1284
 *                     for ref, length in zip(self.references, self.lengths):
 *                         sq.append({'LN': length, 'SN': ref })
 *                     result["SQ"] = sq             # <<<<<<<<<<<<<<
 * 
 *             return result
 */
      if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_n_s_SQ, __pyx_v_sq) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1284; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L22;
    }
    __pyx_L22:;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "pysam/calignmentfile.pyx":1286
 *                     result["SQ"] = sq
 * 
 *             return result             # <<<<<<<<<<<<<<
 * 
 *     def _buildLine(self, fields, record):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1208
 * 
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if not self._isOpen():
 *                 raise ValueError( "I/O operation on closed file" )
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile.header.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_line);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_record);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_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);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1288
 *             return result
 * 
 *     def _buildLine(self, fields, record):             # <<<<<<<<<<<<<<
 *         '''build a header line from *fields* dictionary for *record*'''
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_45_buildLine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_44_buildLine[] = "AlignmentFile._buildLine(self, fields, record)\nbuild a header line from *fields* dictionary for *record*";
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_45_buildLine(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_record = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_buildLine (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fields,&__pyx_n_s_record,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fields)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_record)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1288; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_buildLine") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1288; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_fields = values[0];
    __pyx_v_record = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_buildLine", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1288; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile._buildLine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_44_buildLine(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self), __pyx_v_fields, __pyx_v_record);

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_44_buildLine(CYTHON_UNUSED struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_fields, PyObject *__pyx_v_record) {
  PyObject *__pyx_v_line = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  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_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_buildLine", 0);
  __Pyx_TraceCall("_buildLine", __pyx_f[0], 1288);

  /* "pysam/calignmentfile.pyx":1292
 * 
 *         # TODO: add checking for field and sort order
 *         line = ["@%s" % record]             # <<<<<<<<<<<<<<
 *         # comment
 *         if record == "CO":
 */
  __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_v_record); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_v_line = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":1294
 *         line = ["@%s" % record]
 *         # comment
 *         if record == "CO":             # <<<<<<<<<<<<<<
 *             line.append(fields)
 *         # user tags
 */
  __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_record, __pyx_n_s_CO, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_3) {

    /* "pysam/calignmentfile.pyx":1295
 *         # comment
 *         if record == "CO":
 *             line.append(fields)             # <<<<<<<<<<<<<<
 *         # user tags
 *         elif record.islower():
 */
    __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_line, __pyx_v_fields); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }

  /* "pysam/calignmentfile.pyx":1297
 *             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_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "pysam/calignmentfile.pyx":1298
 *         # 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_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __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 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(__pyx_t_2 == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __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_COMPILING_IN_CPYTHON
      __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_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1298; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/calignmentfile.pyx":1299
 *         elif record.islower():
 *             for key in sorted(fields):
 *                 line.append("%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 *         # defined tags
 *         else:
 */
      __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_key);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_key);
      __Pyx_GIVEREF(__pyx_v_key);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __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 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1299; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pysam/calignmentfile.pyx":1298
 *         # 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;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":1303
 *         else:
 *             # write fields of the specification
 *             for key in VALID_HEADER_ORDER[record]:             # <<<<<<<<<<<<<<
 *                 if key in fields:
 *                     line.append("%s:%s" % (key, str(fields[key])))
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_ORDER); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1303; __pyx_clineno = __LINE__; goto __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_6 = 0;
      __pyx_t_7 = NULL;
    } else {
      __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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_COMPILING_IN_CPYTHON
          __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_filename = __pyx_f[0]; __pyx_lineno = 1303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __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_filename = __pyx_f[0]; __pyx_lineno = 1303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #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(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/calignmentfile.pyx":1304
 *             # write fields of the specification
 *             for key in VALID_HEADER_ORDER[record]:
 *                 if key in fields:             # <<<<<<<<<<<<<<
 *                     line.append("%s:%s" % (key, str(fields[key])))
 *             # write user fields
 */
      __pyx_t_3 = (__Pyx_PySequence_Contains(__pyx_v_key, __pyx_v_fields, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1304; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_8 = (__pyx_t_3 != 0);
      if (__pyx_t_8) {

        /* "pysam/calignmentfile.pyx":1305
 *             for key in VALID_HEADER_ORDER[record]:
 *                 if key in fields:
 *                     line.append("%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 *             # write user fields
 *             for key in fields:
 */
        __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_INCREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_key);
        __Pyx_GIVEREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __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 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        goto __pyx_L8;
      }
      __pyx_L8:;

      /* "pysam/calignmentfile.pyx":1303
 *         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/calignmentfile.pyx":1307
 *                     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_filename = __pyx_f[0]; __pyx_lineno = 1307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1307; __pyx_clineno = __LINE__; goto __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_COMPILING_IN_CPYTHON
          __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_filename = __pyx_f[0]; __pyx_lineno = 1307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __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_filename = __pyx_f[0]; __pyx_lineno = 1307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #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(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1307; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/calignmentfile.pyx":1308
 *             # 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_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_9 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && 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);
        }
      }
      if (__pyx_t_9) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_9); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else {
        __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_3 = ((!__pyx_t_8) != 0);
      if (__pyx_t_3) {

        /* "pysam/calignmentfile.pyx":1309
 *             for key in fields:
 *                 if not key.isupper():
 *                     line.append("%s:%s" % (key, str(fields[key])))             # <<<<<<<<<<<<<<
 * 
 *         return "\t".join(line)
 */
        __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_v_key); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_INCREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_key);
        __Pyx_GIVEREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __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 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1309; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        goto __pyx_L11;
      }
      __pyx_L11:;

      /* "pysam/calignmentfile.pyx":1307
 *                     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/calignmentfile.pyx":1311
 *                     line.append("%s:%s" % (key, str(fields[key])))
 * 
 *         return "\t".join(line)             # <<<<<<<<<<<<<<
 * 
 *     cdef bam_hdr_t * _buildHeader(self, new_header):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__46, __pyx_v_line); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1311; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1288
 *             return result
 * 
 *     def _buildLine(self, fields, record):             # <<<<<<<<<<<<<<
 *         '''build a header line from *fields* dictionary for *record*'''
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile._buildLine", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_line);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1313
 *         return "\t".join(line)
 * 
 *     cdef bam_hdr_t * _buildHeader(self, new_header):             # <<<<<<<<<<<<<<
 *         '''return a new header built from a dictionary in *new_header*.
 * 
 */

static bam_hdr_t *__pyx_f_5pysam_14calignmentfile_13AlignmentFile__buildHeader(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self, PyObject *__pyx_v_new_header) {
  PyObject *__pyx_v_lines = NULL;
  bam_hdr_t *__pyx_v_dest;
  PyObject *__pyx_v_record = NULL;
  PyObject *__pyx_v_ttype = NULL;
  PyObject *__pyx_v_data = NULL;
  PyObject *__pyx_v_fields = NULL;
  PyObject *__pyx_v_text = NULL;
  PyObject *__pyx_v_btext = 0;
  PyObject *__pyx_v_bseqname = 0;
  PyObject *__pyx_v_seqs = NULL;
  long __pyx_v_x;
  PyObject *__pyx_v_seqname = NULL;
  PyObject *__pyx_v_seqlen = NULL;
  bam_hdr_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *(*__pyx_t_4)(PyObject *);
  int __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  Py_ssize_t __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_t_11;
  PyObject *(*__pyx_t_12)(PyObject *);
  Py_ssize_t __pyx_t_13;
  PyObject *__pyx_t_14 = NULL;
  PyObject *(*__pyx_t_15)(PyObject *);
  char const *__pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  int __pyx_t_20;
  int32_t __pyx_t_21;
  uint32_t __pyx_t_22;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_buildHeader", 0);
  __Pyx_TraceCall("_buildHeader", __pyx_f[0], 1313);

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

  /* "pysam/calignmentfile.pyx":1326
 *         cdef bam_hdr_t * dest
 * 
 *         dest = bam_hdr_init()             # <<<<<<<<<<<<<<
 * 
 *         # first: defined tags
 */
  __pyx_v_dest = bam_hdr_init();

  /* "pysam/calignmentfile.pyx":1329
 * 
 *         # first: defined tags
 *         for record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *             if record in new_header:
 *                 ttype = VALID_HEADER_TYPES[record]
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __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_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_4(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_record, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/calignmentfile.pyx":1330
 *         # first: defined tags
 *         for record in VALID_HEADERS:
 *             if record in new_header:             # <<<<<<<<<<<<<<
 *                 ttype = VALID_HEADER_TYPES[record]
 *                 data = new_header[record]
 */
    __pyx_t_5 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_v_new_header, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1330; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {

      /* "pysam/calignmentfile.pyx":1331
 *         for record in VALID_HEADERS:
 *             if record in new_header:
 *                 ttype = VALID_HEADER_TYPES[record]             # <<<<<<<<<<<<<<
 *                 data = new_header[record]
 *                 if type(data) != type(ttype()):
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADER_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = PyObject_GetItem(__pyx_t_1, __pyx_v_record); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1331; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_ttype, __pyx_t_7);
      __pyx_t_7 = 0;

      /* "pysam/calignmentfile.pyx":1332
 *             if record in new_header:
 *                 ttype = VALID_HEADER_TYPES[record]
 *                 data = new_header[record]             # <<<<<<<<<<<<<<
 *                 if type(data) != type(ttype()):
 *                     raise ValueError(
 */
      __pyx_t_7 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_XDECREF_SET(__pyx_v_data, __pyx_t_7);
      __pyx_t_7 = 0;

      /* "pysam/calignmentfile.pyx":1333
 *                 ttype = VALID_HEADER_TYPES[record]
 *                 data = new_header[record]
 *                 if type(data) != type(ttype()):             # <<<<<<<<<<<<<<
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s" %
 */
      __Pyx_INCREF(__pyx_v_ttype);
      __pyx_t_1 = __pyx_v_ttype; __pyx_t_8 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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);
        }
      }
      if (__pyx_t_8) {
        __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else {
        __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_data)), ((PyObject *)Py_TYPE(__pyx_t_7)), Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1333; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_6) {

        /* "pysam/calignmentfile.pyx":1336
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s" %
 *                         (record, type(data), type(ttype())))             # <<<<<<<<<<<<<<
 *                 if type(data) is dict:
 *                     lines.append(self._buildLine(data, record))
 */
        __Pyx_INCREF(__pyx_v_ttype);
        __pyx_t_7 = __pyx_v_ttype; __pyx_t_8 = NULL;
        if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
          }
        }
        if (__pyx_t_8) {
          __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        } else {
          __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_v_record);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_record);
        __Pyx_GIVEREF(__pyx_v_record);
        __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_data)));
        PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)Py_TYPE(__pyx_v_data)));
        __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_v_data)));
        __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_t_1)));
        PyTuple_SET_ITEM(__pyx_t_7, 2, ((PyObject *)Py_TYPE(__pyx_t_1)));
        __Pyx_GIVEREF(((PyObject *)Py_TYPE(__pyx_t_1)));
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "pysam/calignmentfile.pyx":1335
 *                 if type(data) != type(ttype()):
 *                     raise ValueError(
 *                         "invalid type for record %s: %s, expected %s" %             # <<<<<<<<<<<<<<
 *                         (record, type(data), type(ttype())))
 *                 if type(data) is dict:
 */
        __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_invalid_type_for_record_s_s_expe, __pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "pysam/calignmentfile.pyx":1334
 *                 data = new_header[record]
 *                 if type(data) != type(ttype()):
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "invalid type for record %s: %s, expected %s" %
 *                         (record, type(data), type(ttype())))
 */
        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_Raise(__pyx_t_1, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1334; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }

      /* "pysam/calignmentfile.pyx":1337
 *                         "invalid type for record %s: %s, expected %s" %
 *                         (record, type(data), type(ttype())))
 *                 if type(data) is dict:             # <<<<<<<<<<<<<<
 *                     lines.append(self._buildLine(data, record))
 *                 else:
 */
      __pyx_t_6 = (((PyObject *)Py_TYPE(__pyx_v_data)) == ((PyObject *)((PyObject*)(&PyDict_Type))));
      __pyx_t_5 = (__pyx_t_6 != 0);
      if (__pyx_t_5) {

        /* "pysam/calignmentfile.pyx":1338
 *                         (record, type(data), type(ttype())))
 *                 if type(data) is dict:
 *                     lines.append(self._buildLine(data, record))             # <<<<<<<<<<<<<<
 *                 else:
 *                     for fields in new_header[record]:
 */
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_buildLine); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = NULL;
        __pyx_t_9 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
            __pyx_t_9 = 1;
          }
        }
        __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        if (__pyx_t_8) {
          PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = NULL;
        }
        __Pyx_INCREF(__pyx_v_data);
        PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_v_data);
        __Pyx_GIVEREF(__pyx_v_data);
        __Pyx_INCREF(__pyx_v_record);
        PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_v_record);
        __Pyx_GIVEREF(__pyx_v_record);
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_1); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L7;
      }
      /*else*/ {

        /* "pysam/calignmentfile.pyx":1340
 *                     lines.append(self._buildLine(data, record))
 *                 else:
 *                     for fields in new_header[record]:             # <<<<<<<<<<<<<<
 *                         lines.append(self._buildLine(fields, record))
 * 
 */
        __pyx_t_1 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __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_9 = 0;
          __pyx_t_12 = NULL;
        } else {
          __pyx_t_9 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_12 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        for (;;) {
          if (likely(!__pyx_t_12)) {
            if (likely(PyList_CheckExact(__pyx_t_7))) {
              if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_7)) break;
              #if CYTHON_COMPILING_IN_CPYTHON
              __pyx_t_1 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              #else
              __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              #endif
            } else {
              if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
              #if CYTHON_COMPILING_IN_CPYTHON
              __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              #else
              __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              #endif
            }
          } else {
            __pyx_t_1 = __pyx_t_12(__pyx_t_7);
            if (unlikely(!__pyx_t_1)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_1);
          }
          __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_1);
          __pyx_t_1 = 0;

          /* "pysam/calignmentfile.pyx":1341
 *                 else:
 *                     for fields in new_header[record]:
 *                         lines.append(self._buildLine(fields, record))             # <<<<<<<<<<<<<<
 * 
 *         # then: user tags (lower case), sorted alphabetically
 */
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_buildLine); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_8 = NULL;
          __pyx_t_13 = 0;
          if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_10))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_10);
            if (likely(__pyx_t_8)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_10, function);
              __pyx_t_13 = 1;
            }
          }
          __pyx_t_14 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_14);
          if (__pyx_t_8) {
            PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = NULL;
          }
          __Pyx_INCREF(__pyx_v_fields);
          PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_13, __pyx_v_fields);
          __Pyx_GIVEREF(__pyx_v_fields);
          __Pyx_INCREF(__pyx_v_record);
          PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_13, __pyx_v_record);
          __Pyx_GIVEREF(__pyx_v_record);
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_14, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_1); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "pysam/calignmentfile.pyx":1340
 *                     lines.append(self._buildLine(data, record))
 *                 else:
 *                     for fields in new_header[record]:             # <<<<<<<<<<<<<<
 *                         lines.append(self._buildLine(fields, record))
 * 
 */
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __pyx_L7:;
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "pysam/calignmentfile.pyx":1329
 * 
 *         # first: defined tags
 *         for record in VALID_HEADERS:             # <<<<<<<<<<<<<<
 *             if record in new_header:
 *                 ttype = VALID_HEADER_TYPES[record]
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":1344
 * 
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(new_header.items()):             # <<<<<<<<<<<<<<
 *             if record in VALID_HEADERS: continue
 *             if type( data ) is dict:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_new_header, __pyx_n_s_items); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_10)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_10);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_10) {
    __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_10); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  } else {
    __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __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_11 = PyList_Sort(__pyx_t_2); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(__pyx_t_2 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __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_COMPILING_IN_CPYTHON
    __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_10);
      #else
      __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_14 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
      index = 0; __pyx_t_7 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_7)) goto __pyx_L12_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      index = 1; __pyx_t_10 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_10)) goto __pyx_L12_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_10);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_15 = NULL;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      goto __pyx_L13_unpacking_done;
      __pyx_L12_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_15 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __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_10);
    __pyx_t_10 = 0;

    /* "pysam/calignmentfile.pyx":1345
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(new_header.items()):
 *             if record in VALID_HEADERS: continue             # <<<<<<<<<<<<<<
 *             if type( data ) is dict:
 *                 lines.append( self._buildLine( data, record ) )
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_VALID_HEADERS); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = (__Pyx_PySequence_Contains(__pyx_v_record, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {
      goto __pyx_L10_continue;
    }

    /* "pysam/calignmentfile.pyx":1346
 *         for record, data in sorted(new_header.items()):
 *             if record in VALID_HEADERS: continue
 *             if type( data ) is dict:             # <<<<<<<<<<<<<<
 *                 lines.append( self._buildLine( data, record ) )
 *             else:
 */
    __pyx_t_6 = (((PyObject *)Py_TYPE(__pyx_v_data)) == ((PyObject *)((PyObject*)(&PyDict_Type))));
    __pyx_t_5 = (__pyx_t_6 != 0);
    if (__pyx_t_5) {

      /* "pysam/calignmentfile.pyx":1347
 *             if record in VALID_HEADERS: continue
 *             if type( data ) is dict:
 *                 lines.append( self._buildLine( data, record ) )             # <<<<<<<<<<<<<<
 *             else:
 *                 for fields in new_header[record]:
 */
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_buildLine); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_7 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_10))) {
        __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_10);
        if (likely(__pyx_t_7)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_7);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_10, function);
          __pyx_t_9 = 1;
        }
      }
      __pyx_t_14 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_14);
      if (__pyx_t_7) {
        PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_7); __pyx_t_7 = NULL;
      }
      __Pyx_INCREF(__pyx_v_data);
      PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_9, __pyx_v_data);
      __Pyx_GIVEREF(__pyx_v_data);
      __Pyx_INCREF(__pyx_v_record);
      PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_9, __pyx_v_record);
      __Pyx_GIVEREF(__pyx_v_record);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_2); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      goto __pyx_L15;
    }
    /*else*/ {

      /* "pysam/calignmentfile.pyx":1349
 *                 lines.append( self._buildLine( data, record ) )
 *             else:
 *                 for fields in new_header[record]:             # <<<<<<<<<<<<<<
 *                     lines.append( self._buildLine( fields, record ) )
 * 
 */
      __pyx_t_2 = PyObject_GetItem(__pyx_v_new_header, __pyx_v_record); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
        __pyx_t_10 = __pyx_t_2; __Pyx_INCREF(__pyx_t_10); __pyx_t_9 = 0;
        __pyx_t_4 = NULL;
      } else {
        __pyx_t_9 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_4 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      for (;;) {
        if (likely(!__pyx_t_4)) {
          if (likely(PyList_CheckExact(__pyx_t_10))) {
            if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_10)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_2 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_9); __Pyx_INCREF(__pyx_t_2); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_10, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #endif
          } else {
            if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_10)) break;
            #if CYTHON_COMPILING_IN_CPYTHON
            __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_9); __Pyx_INCREF(__pyx_t_2); __pyx_t_9++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #else
            __pyx_t_2 = PySequence_ITEM(__pyx_t_10, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            #endif
          }
        } else {
          __pyx_t_2 = __pyx_t_4(__pyx_t_10);
          if (unlikely(!__pyx_t_2)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_2);
        }
        __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_2);
        __pyx_t_2 = 0;

        /* "pysam/calignmentfile.pyx":1350
 *             else:
 *                 for fields in new_header[record]:
 *                     lines.append( self._buildLine( fields, record ) )             # <<<<<<<<<<<<<<
 * 
 *         text = "\n".join(lines) + "\n"
 */
        __pyx_t_14 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_buildLine); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_14);
        __pyx_t_7 = NULL;
        __pyx_t_13 = 0;
        if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_14))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_14);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_14, function);
            __pyx_t_13 = 1;
          }
        }
        __pyx_t_8 = PyTuple_New(2+__pyx_t_13); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        if (__pyx_t_7) {
          PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_7); __pyx_t_7 = NULL;
        }
        __Pyx_INCREF(__pyx_v_fields);
        PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_13, __pyx_v_fields);
        __Pyx_GIVEREF(__pyx_v_fields);
        __Pyx_INCREF(__pyx_v_record);
        PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_13, __pyx_v_record);
        __Pyx_GIVEREF(__pyx_v_record);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_lines, __pyx_t_2); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "pysam/calignmentfile.pyx":1349
 *                 lines.append( self._buildLine( data, record ) )
 *             else:
 *                 for fields in new_header[record]:             # <<<<<<<<<<<<<<
 *                     lines.append( self._buildLine( fields, record ) )
 * 
 */
      }
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    }
    __pyx_L15:;

    /* "pysam/calignmentfile.pyx":1344
 * 
 *         # then: user tags (lower case), sorted alphabetically
 *         for record, data in sorted(new_header.items()):             # <<<<<<<<<<<<<<
 *             if record in VALID_HEADERS: continue
 *             if type( data ) is dict:
 */
    __pyx_L10_continue:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1352
 *                     lines.append( self._buildLine( fields, record ) )
 * 
 *         text = "\n".join(lines) + "\n"             # <<<<<<<<<<<<<<
 *         if dest.text != NULL: free( dest.text )
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 */
  __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__41, __pyx_v_lines); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = PyNumber_Add(__pyx_t_1, __pyx_kp_s__41); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_text = ((PyObject*)__pyx_t_10);
  __pyx_t_10 = 0;

  /* "pysam/calignmentfile.pyx":1353
 * 
 *         text = "\n".join(lines) + "\n"
 *         if dest.text != NULL: free( dest.text )             # <<<<<<<<<<<<<<
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 *         dest.l_text = len(text)
 */
  __pyx_t_5 = ((__pyx_v_dest->text != NULL) != 0);
  if (__pyx_t_5) {
    free(__pyx_v_dest->text);
    goto __pyx_L18;
  }
  __pyx_L18:;

  /* "pysam/calignmentfile.pyx":1354
 *         text = "\n".join(lines) + "\n"
 *         if dest.text != NULL: free( dest.text )
 *         dest.text = <char*>calloc( len(text), sizeof(char))             # <<<<<<<<<<<<<<
 *         dest.l_text = len(text)
 *         cdef bytes btext = text.encode('ascii')
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest->text = ((char *)calloc(__pyx_t_3, (sizeof(char))));

  /* "pysam/calignmentfile.pyx":1355
 *         if dest.text != NULL: free( dest.text )
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 *         dest.l_text = len(text)             # <<<<<<<<<<<<<<
 *         cdef bytes btext = text.encode('ascii')
 *         strncpy( dest.text, btext, dest.l_text )
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_text); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_dest->l_text = __pyx_t_3;

  /* "pysam/calignmentfile.pyx":1356
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 *         dest.l_text = len(text)
 *         cdef bytes btext = text.encode('ascii')             # <<<<<<<<<<<<<<
 *         strncpy( dest.text, btext, dest.l_text )
 * 
 */
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_text, __pyx_n_s_encode); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__54, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_btext = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1357
 *         dest.l_text = len(text)
 *         cdef bytes btext = text.encode('ascii')
 *         strncpy( dest.text, btext, dest.l_text )             # <<<<<<<<<<<<<<
 * 
 *         cdef bytes bseqname
 */
  __pyx_t_16 = __Pyx_PyObject_AsString(__pyx_v_btext); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  strncpy(__pyx_v_dest->text, __pyx_t_16, __pyx_v_dest->l_text);

  /* "pysam/calignmentfile.pyx":1361
 *         cdef bytes bseqname
 *         # collect targets
 *         if "SQ" in new_header:             # <<<<<<<<<<<<<<
 *             seqs = []
 *             for fields in new_header["SQ"]:
 */
  __pyx_t_5 = (__Pyx_PySequence_Contains(__pyx_n_s_SQ, __pyx_v_new_header, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "pysam/calignmentfile.pyx":1362
 *         # collect targets
 *         if "SQ" in new_header:
 *             seqs = []             # <<<<<<<<<<<<<<
 *             for fields in new_header["SQ"]:
 *                 try:
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_seqs = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/calignmentfile.pyx":1363
 *         if "SQ" in new_header:
 *             seqs = []
 *             for fields in new_header["SQ"]:             # <<<<<<<<<<<<<<
 *                 try:
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 */
    __pyx_t_1 = PyObject_GetItem(__pyx_v_new_header, __pyx_n_s_SQ); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_10 = __pyx_t_1; __Pyx_INCREF(__pyx_t_10); __pyx_t_3 = 0;
      __pyx_t_4 = NULL;
    } else {
      __pyx_t_3 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_4 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_4)) {
        if (likely(PyList_CheckExact(__pyx_t_10))) {
          if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_10)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_10, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_10)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_10, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_4(__pyx_t_10);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1363; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF_SET(__pyx_v_fields, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysam/calignmentfile.pyx":1364
 *             seqs = []
 *             for fields in new_header["SQ"]:
 *                 try:             # <<<<<<<<<<<<<<
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 *                 except KeyError:
 */
      {
        __Pyx_ExceptionSave(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19);
        __Pyx_XGOTREF(__pyx_t_17);
        __Pyx_XGOTREF(__pyx_t_18);
        __Pyx_XGOTREF(__pyx_t_19);
        /*try:*/ {

          /* "pysam/calignmentfile.pyx":1365
 *             for fields in new_header["SQ"]:
 *                 try:
 *                     seqs.append( (fields["SN"], fields["LN"] ) )             # <<<<<<<<<<<<<<
 *                 except KeyError:
 *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
 */
          __pyx_t_1 = PyObject_GetItem(__pyx_v_fields, __pyx_n_s_SN); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L22_error;};
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_2 = PyObject_GetItem(__pyx_v_fields, __pyx_n_s_LN); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L22_error;};
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_14 = PyTuple_New(2); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
          __Pyx_GOTREF(__pyx_t_14);
          PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_1);
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_14, 1, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_2);
          __pyx_t_1 = 0;
          __pyx_t_2 = 0;
          __pyx_t_11 = __Pyx_PyList_Append(__pyx_v_seqs, __pyx_t_14); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1365; __pyx_clineno = __LINE__; goto __pyx_L22_error;}
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        }
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        goto __pyx_L29_try_end;
        __pyx_L22_error:;
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;

        /* "pysam/calignmentfile.pyx":1366
 *                 try:
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 *                 except KeyError:             # <<<<<<<<<<<<<<
 *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
 * 
 */
        __pyx_t_20 = PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_20) {
          __Pyx_AddTraceback("pysam.calignmentfile.AlignmentFile._buildHeader", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_14, &__pyx_t_2, &__pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GOTREF(__pyx_t_1);

          /* "pysam/calignmentfile.pyx":1367
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 *                 except KeyError:
 *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))             # <<<<<<<<<<<<<<
 * 
 *             dest.n_targets = len(seqs)
 */
          __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_INCREF(__pyx_v_fields);
          PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_fields);
          __Pyx_GIVEREF(__pyx_v_fields);
          __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_incomplete_sequence_information, __pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_7);
          PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_8);
          __Pyx_GIVEREF(__pyx_t_8);
          __pyx_t_8 = 0;
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_Raise(__pyx_t_8, 0, 0, 0);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1367; __pyx_clineno = __LINE__; goto __pyx_L24_except_error;}
        }
        goto __pyx_L24_except_error;
        __pyx_L24_except_error:;
        __Pyx_XGIVEREF(__pyx_t_17);
        __Pyx_XGIVEREF(__pyx_t_18);
        __Pyx_XGIVEREF(__pyx_t_19);
        __Pyx_ExceptionReset(__pyx_t_17, __pyx_t_18, __pyx_t_19);
        goto __pyx_L1_error;
        __pyx_L29_try_end:;
      }

      /* "pysam/calignmentfile.pyx":1363
 *         if "SQ" in new_header:
 *             seqs = []
 *             for fields in new_header["SQ"]:             # <<<<<<<<<<<<<<
 *                 try:
 *                     seqs.append( (fields["SN"], fields["LN"] ) )
 */
    }
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "pysam/calignmentfile.pyx":1369
 *                     raise KeyError( "incomplete sequence information in '%s'" % str(fields))
 * 
 *             dest.n_targets = len(seqs)             # <<<<<<<<<<<<<<
 *             dest.target_name = <char**>calloc(dest.n_targets, sizeof(char*))
 *             dest.target_len = <uint32_t*>calloc(dest.n_targets, sizeof(uint32_t))
 */
    __pyx_t_3 = PyList_GET_SIZE(__pyx_v_seqs); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1369; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_dest->n_targets = __pyx_t_3;

    /* "pysam/calignmentfile.pyx":1370
 * 
 *             dest.n_targets = len(seqs)
 *             dest.target_name = <char**>calloc(dest.n_targets, sizeof(char*))             # <<<<<<<<<<<<<<
 *             dest.target_len = <uint32_t*>calloc(dest.n_targets, sizeof(uint32_t))
 * 
 */
    __pyx_v_dest->target_name = ((char **)calloc(__pyx_v_dest->n_targets, (sizeof(char *))));

    /* "pysam/calignmentfile.pyx":1371
 *             dest.n_targets = len(seqs)
 *             dest.target_name = <char**>calloc(dest.n_targets, sizeof(char*))
 *             dest.target_len = <uint32_t*>calloc(dest.n_targets, sizeof(uint32_t))             # <<<<<<<<<<<<<<
 * 
 *             for x from 0 <= x < dest.n_targets:
 */
    __pyx_v_dest->target_len = ((uint32_t *)calloc(__pyx_v_dest->n_targets, (sizeof(uint32_t))));

    /* "pysam/calignmentfile.pyx":1373
 *             dest.target_len = <uint32_t*>calloc(dest.n_targets, sizeof(uint32_t))
 * 
 *             for x from 0 <= x < dest.n_targets:             # <<<<<<<<<<<<<<
 *                 seqname, seqlen = seqs[x]
 *                 dest.target_name[x] = <char*>calloc(
 */
    __pyx_t_21 = __pyx_v_dest->n_targets;
    for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_21; __pyx_v_x++) {

      /* "pysam/calignmentfile.pyx":1374
 * 
 *             for x from 0 <= x < dest.n_targets:
 *                 seqname, seqlen = seqs[x]             # <<<<<<<<<<<<<<
 *                 dest.target_name[x] = <char*>calloc(
 *                     len(seqname) + 1, sizeof(char))
 */
      __pyx_t_10 = __Pyx_GetItemInt_List(__pyx_v_seqs, __pyx_v_x, long, 1, __Pyx_PyInt_From_long, 1, 1, 1); if (unlikely(__pyx_t_10 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_10);
      if ((likely(PyTuple_CheckExact(__pyx_t_10))) || (PyList_CheckExact(__pyx_t_10))) {
        PyObject* sequence = __pyx_t_10;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_2);
        #else
        __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        #endif
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_14 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_15 = Py_TYPE(__pyx_t_14)->tp_iternext;
        index = 0; __pyx_t_1 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_1)) goto __pyx_L34_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_1);
        index = 1; __pyx_t_2 = __pyx_t_15(__pyx_t_14); if (unlikely(!__pyx_t_2)) goto __pyx_L34_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_2);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_14), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_15 = NULL;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        goto __pyx_L35_unpacking_done;
        __pyx_L34_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_15 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L35_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_seqname, __pyx_t_1);
      __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_seqlen, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "pysam/calignmentfile.pyx":1376
 *                 seqname, seqlen = seqs[x]
 *                 dest.target_name[x] = <char*>calloc(
 *                     len(seqname) + 1, sizeof(char))             # <<<<<<<<<<<<<<
 *                 bseqname = seqname.encode('ascii')
 *                 strncpy(dest.target_name[x], bseqname,
 */
      __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysam/calignmentfile.pyx":1375
 *             for x from 0 <= x < dest.n_targets:
 *                 seqname, seqlen = seqs[x]
 *                 dest.target_name[x] = <char*>calloc(             # <<<<<<<<<<<<<<
 *                     len(seqname) + 1, sizeof(char))
 *                 bseqname = seqname.encode('ascii')
 */
      (__pyx_v_dest->target_name[__pyx_v_x]) = ((char *)calloc((__pyx_t_3 + 1), (sizeof(char))));

      /* "pysam/calignmentfile.pyx":1377
 *                 dest.target_name[x] = <char*>calloc(
 *                     len(seqname) + 1, sizeof(char))
 *                 bseqname = seqname.encode('ascii')             # <<<<<<<<<<<<<<
 *                 strncpy(dest.target_name[x], bseqname,
 *                         len(seqname) + 1)
 */
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_seqname, __pyx_n_s_encode); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_tuple__55, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (!(likely(PyBytes_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_2)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_XDECREF_SET(__pyx_v_bseqname, ((PyObject*)__pyx_t_2));
      __pyx_t_2 = 0;

      /* "pysam/calignmentfile.pyx":1378
 *                     len(seqname) + 1, sizeof(char))
 *                 bseqname = seqname.encode('ascii')
 *                 strncpy(dest.target_name[x], bseqname,             # <<<<<<<<<<<<<<
 *                         len(seqname) + 1)
 *                 dest.target_len[x] = seqlen
 */
      __pyx_t_16 = __Pyx_PyObject_AsString(__pyx_v_bseqname); if (unlikely((!__pyx_t_16) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1378; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysam/calignmentfile.pyx":1379
 *                 bseqname = seqname.encode('ascii')
 *                 strncpy(dest.target_name[x], bseqname,
 *                         len(seqname) + 1)             # <<<<<<<<<<<<<<
 *                 dest.target_len[x] = seqlen
 * 
 */
      __pyx_t_3 = PyObject_Length(__pyx_v_seqname); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "pysam/calignmentfile.pyx":1378
 *                     len(seqname) + 1, sizeof(char))
 *                 bseqname = seqname.encode('ascii')
 *                 strncpy(dest.target_name[x], bseqname,             # <<<<<<<<<<<<<<
 *                         len(seqname) + 1)
 *                 dest.target_len[x] = seqlen
 */
      strncpy((__pyx_v_dest->target_name[__pyx_v_x]), __pyx_t_16, (__pyx_t_3 + 1));

      /* "pysam/calignmentfile.pyx":1380
 *                 strncpy(dest.target_name[x], bseqname,
 *                         len(seqname) + 1)
 *                 dest.target_len[x] = seqlen             # <<<<<<<<<<<<<<
 * 
 *         return dest
 */
      __pyx_t_22 = __Pyx_PyInt_As_uint32_t(__pyx_v_seqlen); if (unlikely((__pyx_t_22 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1380; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      (__pyx_v_dest->target_len[__pyx_v_x]) = __pyx_t_22;
    }
    goto __pyx_L19;
  }
  __pyx_L19:;

  /* "pysam/calignmentfile.pyx":1382
 *                 dest.target_len[x] = seqlen
 * 
 *         return dest             # <<<<<<<<<<<<<<
 * 
 *     ###############################################################
 */
  __pyx_r = __pyx_v_dest;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1313
 *         return "\t".join(line)
 * 
 *     cdef bam_hdr_t * _buildHeader(self, new_header):             # <<<<<<<<<<<<<<
 *         '''return a new header built from a dictionary in *new_header*.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_WriteUnraisable("pysam.calignmentfile.AlignmentFile._buildHeader", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_lines);
  __Pyx_XDECREF(__pyx_v_record);
  __Pyx_XDECREF(__pyx_v_ttype);
  __Pyx_XDECREF(__pyx_v_data);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_text);
  __Pyx_XDECREF(__pyx_v_btext);
  __Pyx_XDECREF(__pyx_v_bseqname);
  __Pyx_XDECREF(__pyx_v_seqs);
  __Pyx_XDECREF(__pyx_v_seqname);
  __Pyx_XDECREF(__pyx_v_seqlen);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1392
 *     ## Possible solutions: deprecate or open new file handle
 *     ###############################################################
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_47__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_47__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_46__iter__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_46__iter__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1392);

  /* "pysam/calignmentfile.pyx":1393
 *     ###############################################################
 *     def __iter__(self):
 *         if not self._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError( "I/O operation on closed file" )
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":1394
 *     def __iter__(self):
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         if not self.is_bam and self.header.n_targets == 0:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__56, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1396
 *             raise ValueError( "I/O operation on closed file" )
 * 
 *         if not self.is_bam and self.header.n_targets == 0:             # <<<<<<<<<<<<<<
 *             raise NotImplementedError(
 *                 "can not iterate over samfile without header")
 */
  __pyx_t_4 = ((!(__pyx_v_self->is_bam != 0)) != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_5 = __pyx_t_4;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_4 = ((__pyx_v_self->header->n_targets == 0) != 0);
  __pyx_t_5 = __pyx_t_4;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":1397
 * 
 *         if not self.is_bam and self.header.n_targets == 0:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "can not iterate over samfile without header")
 *         return self
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__57, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1399
 *             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/calignmentfile.pyx":1392
 *     ## Possible solutions: deprecate or open new file handle
 *     ###############################################################
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )
 */

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

/* "pysam/calignmentfile.pyx":1401
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_14calignmentfile_13AlignmentFile_getCurrent(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1401);

  /* "pysam/calignmentfile.pyx":1402
 * 
 *     cdef bam1_t * getCurrent( self ):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->b;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1401
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

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

/* "pysam/calignmentfile.pyx":1404
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''
 *         cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`.
 */

static int __pyx_f_5pysam_14calignmentfile_13AlignmentFile_cnext(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1404);

  /* "pysam/calignmentfile.pyx":1408
 *         cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`.
 *         '''
 *         return sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                          self.header,
 *                          self.b)
 */
  __pyx_r = sam_read1(__pyx_v_self->htsfile, __pyx_v_self->header, __pyx_v_self->b);
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1404
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''
 *         cversion of iterator. Used by :class:`pysam.AlignmentFile.IteratorColumn`.
 */

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

/* "pysam/calignmentfile.pyx":1412
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """
 *         python version of next().
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_49__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_48__next__[] = "\n        python version of next().\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_14calignmentfile_13AlignmentFile_48__next__;
#endif
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_49__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_48__next__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_48__next__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1412);

  /* "pysam/calignmentfile.pyx":1416
 *         python version of next().
 *         """
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if (ret >= 0):
 *             return makeAlignedSegment(self.b)
 */
  __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);

  /* "pysam/calignmentfile.pyx":1417
 *         """
 *         cdef int ret = self.cnext()
 *         if (ret >= 0):             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b)
 *         elif ret == -2:
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1418
 *         cdef int ret = self.cnext()
 *         if (ret >= 0):
 *             return makeAlignedSegment(self.b)             # <<<<<<<<<<<<<<
 *         elif ret == -2:
 *             raise IOError('truncated file')
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_5pysam_14calignmentfile_makeAlignedSegment(__pyx_v_self->b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":1419
 *         if (ret >= 0):
 *             return makeAlignedSegment(self.b)
 *         elif ret == -2:             # <<<<<<<<<<<<<<
 *             raise IOError('truncated file')
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_ret == -2) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1420
 *             return makeAlignedSegment(self.b)
 *         elif ret == -2:
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__58, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":1422
 *             raise IOError('truncated file')
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1412
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """
 *         python version of next().
 */

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

/* "pysam/calignmentfile.pxd":96
 *     cdef bam_hdr_t * header
 *     # true if file is bam format
 *     cdef readonly bint is_bam             # <<<<<<<<<<<<<<
 *     # true if file is bam format
 *     cdef readonly bint is_cram
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_6is_bam_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_6is_bam_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6is_bam___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_6is_bam___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 96);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_bam); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pxd":98
 *     cdef readonly bint is_bam
 *     # true if file is bam format
 *     cdef readonly bint is_cram             # <<<<<<<<<<<<<<
 *     # true if not a file but a stream
 *     cdef readonly bint is_stream
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_7is_cram_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_7is_cram_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_7is_cram___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_7is_cram___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 98);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_cram); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pxd":100
 *     cdef readonly bint is_cram
 *     # true if not a file but a stream
 *     cdef readonly bint is_stream             # <<<<<<<<<<<<<<
 *     # true if file is not on the local filesystem
 *     cdef readonly bint is_remote
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_9is_stream_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_9is_stream_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_9is_stream___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_9is_stream___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 100);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_stream); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pxd":102
 *     cdef readonly bint is_stream
 *     # true if file is not on the local filesystem
 *     cdef readonly bint is_remote             # <<<<<<<<<<<<<<
 *     # current read within iteration
 *     cdef bam1_t * b
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_9is_remote_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_9is_remote_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_13AlignmentFile_9is_remote___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_13AlignmentFile_9is_remote___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[1], 102);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->is_remote); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":1450
 *     '''
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=False):             # <<<<<<<<<<<<<<
 * 
 *         if not samfile._isOpen():
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_11IteratorRow_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_11IteratorRow_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_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);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_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_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_14calignmentfile_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_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.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_14calignmentfile_AlignmentFile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_11IteratorRow___init__(((struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_11IteratorRow___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRow *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  char const *__pyx_t_6;
  htsFile *__pyx_t_7;
  bam_hdr_t *__pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1450);

  /* "pysam/calignmentfile.pyx":1452
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=False):
 * 
 *         if not samfile._isOpen():             # <<<<<<<<<<<<<<
 *             raise ValueError("I/O operation on closed file")
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_isOpen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = ((!__pyx_t_4) != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":1453
 * 
 *         if not samfile._isOpen():
 *             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__59, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1457
 *         # 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/calignmentfile.pyx":1461
 *         # reopen the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:             # <<<<<<<<<<<<<<
 *             self.htsfile = hts_open(samfile._filename, 'r')
 *             assert self.htsfile != NULL
 */
  __pyx_t_5 = (__pyx_v_multiple_iterators != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":1462
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:
 *             self.htsfile = hts_open(samfile._filename, 'r')             # <<<<<<<<<<<<<<
 *             assert self.htsfile != NULL
 *             # read header - required for accurate positioning
 */
    __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_samfile->_filename); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_self->htsfile = hts_open(__pyx_t_6, __pyx_k_r);

    /* "pysam/calignmentfile.pyx":1463
 *         if multiple_iterators:
 *             self.htsfile = hts_open(samfile._filename, 'r')
 *             assert self.htsfile != NULL             # <<<<<<<<<<<<<<
 *             # read header - required for accurate positioning
 *             # could a tell/seek work?
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      if (unlikely(!((__pyx_v_self->htsfile != NULL) != 0))) {
        PyErr_SetNone(PyExc_AssertionError);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
    }
    #endif

    /* "pysam/calignmentfile.pyx":1466
 *             # read header - required for accurate positioning
 *             # could a tell/seek work?
 *             self.header = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *             assert self.header != NULL
 *             self.owns_samfile = True
 */
    __pyx_v_self->header = sam_hdr_read(__pyx_v_self->htsfile);

    /* "pysam/calignmentfile.pyx":1467
 *             # could a tell/seek work?
 *             self.header = sam_hdr_read(self.htsfile)
 *             assert self.header != NULL             # <<<<<<<<<<<<<<
 *             self.owns_samfile = True
 *         else:
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      if (unlikely(!((__pyx_v_self->header != NULL) != 0))) {
        PyErr_SetNone(PyExc_AssertionError);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
    }
    #endif

    /* "pysam/calignmentfile.pyx":1468
 *             self.header = sam_hdr_read(self.htsfile)
 *             assert self.header != NULL
 *             self.owns_samfile = True             # <<<<<<<<<<<<<<
 *         else:
 *             self.htsfile = self.samfile.htsfile
 */
    __pyx_v_self->owns_samfile = 1;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":1470
 *             self.owns_samfile = True
 *         else:
 *             self.htsfile = self.samfile.htsfile             # <<<<<<<<<<<<<<
 *             self.owns_samfile = False
 *             self.header = self.samfile.header
 */
    __pyx_t_7 = __pyx_v_self->samfile->htsfile;
    __pyx_v_self->htsfile = __pyx_t_7;

    /* "pysam/calignmentfile.pyx":1471
 *         else:
 *             self.htsfile = self.samfile.htsfile
 *             self.owns_samfile = False             # <<<<<<<<<<<<<<
 *             self.header = self.samfile.header
 * 
 */
    __pyx_v_self->owns_samfile = 0;

    /* "pysam/calignmentfile.pyx":1472
 *             self.htsfile = self.samfile.htsfile
 *             self.owns_samfile = False
 *             self.header = self.samfile.header             # <<<<<<<<<<<<<<
 * 
 *         self.retval = 0
 */
    __pyx_t_8 = __pyx_v_self->samfile->header;
    __pyx_v_self->header = __pyx_t_8;
  }
  __pyx_L4:;

  /* "pysam/calignmentfile.pyx":1474
 *             self.header = self.samfile.header
 * 
 *         self.retval = 0             # <<<<<<<<<<<<<<
 * 
 *         self.b = bam_init1()
 */
  __pyx_v_self->retval = 0;

  /* "pysam/calignmentfile.pyx":1476
 *         self.retval = 0
 * 
 *         self.b = bam_init1()             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_v_self->b = bam_init1();

  /* "pysam/calignmentfile.pyx":1450
 *     '''
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=False):             # <<<<<<<<<<<<<<
 * 
 *         if not samfile._isOpen():
 */

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

/* "pysam/calignmentfile.pyx":1478
 *         self.b = bam_init1()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 */

/* Python wrapper */
static void __pyx_pw_5pysam_14calignmentfile_11IteratorRow_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_14calignmentfile_11IteratorRow_3__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_14calignmentfile_11IteratorRow_2__dealloc__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRow *)__pyx_v_self));

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

static void __pyx_pf_5pysam_14calignmentfile_11IteratorRow_2__dealloc__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRow *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1478);

  /* "pysam/calignmentfile.pyx":1479
 * 
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)             # <<<<<<<<<<<<<<
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 */
  bam_destroy1(__pyx_v_self->b);

  /* "pysam/calignmentfile.pyx":1480
 *     def __dealloc__(self):
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:             # <<<<<<<<<<<<<<
 *             hts_close(self.htsfile)
 *             bam_hdr_destroy(self.header)
 */
  __pyx_t_1 = (__pyx_v_self->owns_samfile != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1481
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 *             bam_hdr_destroy(self.header)
 * 
 */
    hts_close(__pyx_v_self->htsfile);

    /* "pysam/calignmentfile.pyx":1482
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 *             bam_hdr_destroy(self.header)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    bam_hdr_destroy(__pyx_v_self->header);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":1478
 *         self.b = bam_init1()
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self.b)
 *         if self.owns_samfile:
 */

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

/* "pysam/calignmentfile.pyx":1499
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int end,
 *                  int multiple_iterators=False):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_tid;
  int __pyx_v_beg;
  int __pyx_v_end;
  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_end,&__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);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tid)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_beg)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 4, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_tid = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_tid == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1500; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_beg = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_beg == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1500; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1500; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1501; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysam/calignmentfile.pyx":1501
 *     def __init__(self, AlignmentFile samfile,
 *                  int tid, int beg, int end,
 *                  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, 4, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.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_14calignmentfile_AlignmentFile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_17IteratorRowRegion___init__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_beg, __pyx_v_end, __pyx_v_multiple_iterators);

  /* "pysam/calignmentfile.pyx":1499
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int end,
 *                  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_14calignmentfile_17IteratorRowRegion___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_beg, int __pyx_v_end, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1499);

  /* "pysam/calignmentfile.pyx":1503
 *                  int multiple_iterators=False):
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRow)), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/calignmentfile.pyx":1504
 * 
 *         IteratorRow.__init__(self, samfile,
 *                              multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *         if not samfile._hasIndex():
 */
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":1503
 *                  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_filename = __pyx_f[0]; __pyx_lineno = 1503; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":1506
 *                              multiple_iterators=multiple_iterators)
 * 
 *         if not samfile._hasIndex():             # <<<<<<<<<<<<<<
 *             raise ValueError("no index available for iteration")
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_hasIndex); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (__pyx_t_6) {

    /* "pysam/calignmentfile.pyx":1507
 * 
 *         if not samfile._hasIndex():
 *             raise ValueError("no index available for iteration")             # <<<<<<<<<<<<<<
 * 
 *         self.iter = sam_itr_queryi(
 */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__60, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1509
 *             raise ValueError("no index available for iteration")
 * 
 *         self.iter = sam_itr_queryi(             # <<<<<<<<<<<<<<
 *             self.samfile.index,
 *             tid,
 */
  __pyx_v_self->iter = sam_itr_queryi(__pyx_v_self->__pyx_base.samfile->index, __pyx_v_tid, __pyx_v_beg, __pyx_v_end);

  /* "pysam/calignmentfile.pyx":1499
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int tid, int beg, int end,
 *                  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.calignmentfile.IteratorRowRegion.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1515
 *             end)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_17IteratorRowRegion_2__iter__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_17IteratorRowRegion_2__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1515);

  /* "pysam/calignmentfile.pyx":1516
 * 
 *     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/calignmentfile.pyx":1515
 *             end)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

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

/* "pysam/calignmentfile.pyx":1518
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_14calignmentfile_17IteratorRowRegion_getCurrent(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1518);

  /* "pysam/calignmentfile.pyx":1519
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1518
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

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

/* "pysam/calignmentfile.pyx":1521
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         self.retval = hts_itr_next(hts_get_bgzfp(self.htsfile),
 */

static int __pyx_f_5pysam_14calignmentfile_17IteratorRowRegion_cnext(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1521);

  /* "pysam/calignmentfile.pyx":1523
 *     cdef int cnext(self):
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         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/calignmentfile.pyx":1521
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         self.retval = hts_itr_next(hts_get_bgzfp(self.htsfile),
 */

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

/* "pysam/calignmentfile.pyx":1528
 *                                    self.htsfile)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_5__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_17IteratorRowRegion_4__next__[] = "python version of next().\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_14calignmentfile_17IteratorRowRegion_4__next__;
#endif
static PyObject *__pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_17IteratorRowRegion_4__next__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_17IteratorRowRegion_4__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1528);

  /* "pysam/calignmentfile.pyx":1531
 *         """python version of next().
 *         """
 *         self.cnext()             # <<<<<<<<<<<<<<
 *         if self.retval >= 0:
 *             return makeAlignedSegment(self.b)
 */
  ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);

  /* "pysam/calignmentfile.pyx":1532
 *         """
 *         self.cnext()
 *         if self.retval >= 0:             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b)
 *         elif self.retval == -2:
 */
  __pyx_t_1 = ((__pyx_v_self->__pyx_base.retval >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1533
 *         self.cnext()
 *         if self.retval >= 0:
 *             return makeAlignedSegment(self.b)             # <<<<<<<<<<<<<<
 *         elif self.retval == -2:
 *             # Note: it is currently not the case that hts_iter_next
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_5pysam_14calignmentfile_makeAlignedSegment(__pyx_v_self->__pyx_base.b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":1534
 *         if self.retval >= 0:
 *             return makeAlignedSegment(self.b)
 *         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 == -2) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1538
 *             # returns -2 for a truncated file.
 *             # See https://github.com/pysam-developers/pysam/pull/50#issuecomment-64928625
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__61, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":1540
 *             raise IOError('truncated file')
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1528
 *                                    self.htsfile)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

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

/* "pysam/calignmentfile.pyx":1542
 *             raise StopIteration
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         hts_itr_destroy(self.iter)
 * 
 */

/* Python wrapper */
static void __pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_7__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_14calignmentfile_17IteratorRowRegion_6__dealloc__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_v_self));

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

static void __pyx_pf_5pysam_14calignmentfile_17IteratorRowRegion_6__dealloc__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 1542);

  /* "pysam/calignmentfile.pyx":1543
 * 
 *     def __dealloc__(self):
 *         hts_itr_destroy(self.iter)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  hts_itr_destroy(__pyx_v_self->iter);

  /* "pysam/calignmentfile.pyx":1542
 *             raise StopIteration
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         hts_itr_destroy(self.iter)
 * 
 */

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

/* "pysam/calignmentfile.pyx":1558
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, int n,             # <<<<<<<<<<<<<<
 *                  int multiple_iterators=False):
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_15IteratorRowHead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_15IteratorRowHead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)values[0]);
    __pyx_v_n = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1559; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysam/calignmentfile.pyx":1559
 * 
 *     def __init__(self, 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_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.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_14calignmentfile_AlignmentFile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_15IteratorRowHead___init__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *)__pyx_v_self), __pyx_v_samfile, __pyx_v_n, __pyx_v_multiple_iterators);

  /* "pysam/calignmentfile.pyx":1558
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, int n,             # <<<<<<<<<<<<<<
 *                  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_14calignmentfile_15IteratorRowHead___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_n, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1558);

  /* "pysam/calignmentfile.pyx":1561
 *                  int multiple_iterators=False):
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRow)), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/calignmentfile.pyx":1562
 * 
 *         IteratorRow.__init__(self, samfile,
 *                              multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *         self.max_rows = n
 */
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":1561
 *                  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_filename = __pyx_f[0]; __pyx_lineno = 1561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":1564
 *                              multiple_iterators=multiple_iterators)
 * 
 *         self.max_rows = n             # <<<<<<<<<<<<<<
 *         self.current_row = 0
 * 
 */
  __pyx_v_self->max_rows = __pyx_v_n;

  /* "pysam/calignmentfile.pyx":1565
 * 
 *         self.max_rows = n
 *         self.current_row = 0             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->current_row = 0;

  /* "pysam/calignmentfile.pyx":1558
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, int n,             # <<<<<<<<<<<<<<
 *                  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.calignmentfile.IteratorRowHead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1567
 *         self.current_row = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_15IteratorRowHead_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_15IteratorRowHead_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_15IteratorRowHead_2__iter__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_15IteratorRowHead_2__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1567);

  /* "pysam/calignmentfile.pyx":1568
 * 
 *     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/calignmentfile.pyx":1567
 *         self.current_row = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

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

/* "pysam/calignmentfile.pyx":1570
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_14calignmentfile_15IteratorRowHead_getCurrent(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1570);

  /* "pysam/calignmentfile.pyx":1571
 * 
 *     cdef bam1_t * getCurrent( self ):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1570
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

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

/* "pysam/calignmentfile.pyx":1573
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,
 */

static int __pyx_f_5pysam_14calignmentfile_15IteratorRowHead_cnext(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1573);

  /* "pysam/calignmentfile.pyx":1575
 *     cdef int cnext(self):
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                          self.samfile.header,
 *                          self.b)
 */
  __pyx_r = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->__pyx_base.samfile->header, __pyx_v_self->__pyx_base.b);
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1573
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,
 */

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

/* "pysam/calignmentfile.pyx":1579
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_15IteratorRowHead_5__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_15IteratorRowHead_4__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_14calignmentfile_15IteratorRowHead_4__next__;
#endif
static PyObject *__pyx_pw_5pysam_14calignmentfile_15IteratorRowHead_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_15IteratorRowHead_4__next__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_15IteratorRowHead_4__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1579);

  /* "pysam/calignmentfile.pyx":1584
 *         pyrex uses this non-standard name instead of next()
 *         """
 *         if self.current_row >= self.max_rows:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  __pyx_t_1 = ((__pyx_v_self->current_row >= __pyx_v_self->max_rows) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1585
 *         """
 *         if self.current_row >= self.max_rows:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *         cdef int ret = self.cnext()
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1587
 *             raise StopIteration
 * 
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if (ret >= 0):
 *             self.current_row += 1
 */
  __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowHead *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);

  /* "pysam/calignmentfile.pyx":1588
 * 
 *         cdef int ret = self.cnext()
 *         if (ret >= 0):             # <<<<<<<<<<<<<<
 *             self.current_row += 1
 *             return makeAlignedSegment( self.b )
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1589
 *         cdef int ret = self.cnext()
 *         if (ret >= 0):
 *             self.current_row += 1             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment( self.b )
 *         elif (ret == -2):
 */
    __pyx_v_self->current_row = (__pyx_v_self->current_row + 1);

    /* "pysam/calignmentfile.pyx":1590
 *         if (ret >= 0):
 *             self.current_row += 1
 *             return makeAlignedSegment( self.b )             # <<<<<<<<<<<<<<
 *         elif (ret == -2):
 *             raise IOError('truncated file')
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_5pysam_14calignmentfile_makeAlignedSegment(__pyx_v_self->__pyx_base.b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":1591
 *             self.current_row += 1
 *             return makeAlignedSegment( self.b )
 *         elif (ret == -2):             # <<<<<<<<<<<<<<
 *             raise IOError('truncated file')
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_ret == -2) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1592
 *             return makeAlignedSegment( self.b )
 *         elif (ret == -2):
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__62, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":1594
 *             raise IOError('truncated file')
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1594; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1579
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

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

/* "pysam/calignmentfile.pyx":1610
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  int multiple_iterators=False):
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14IteratorRowAll_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14IteratorRowAll_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_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);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_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_filename = __pyx_f[0]; __pyx_lineno = 1610; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_14calignmentfile_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_filename = __pyx_f[0]; __pyx_lineno = 1611; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysam/calignmentfile.pyx":1611
 * 
 *     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_filename = __pyx_f[0]; __pyx_lineno = 1610; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.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_14calignmentfile_AlignmentFile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14IteratorRowAll___init__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators);

  /* "pysam/calignmentfile.pyx":1610
 *     """
 * 
 *     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_14calignmentfile_14IteratorRowAll___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1610);

  /* "pysam/calignmentfile.pyx":1613
 *                  int multiple_iterators=False):
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRow)), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/calignmentfile.pyx":1614
 * 
 *         IteratorRow.__init__(self, samfile,
 *                              multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_multiple_iterators); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":1613
 *                  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_filename = __pyx_f[0]; __pyx_lineno = 1613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":1610
 *     """
 * 
 *     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.calignmentfile.IteratorRowAll.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1616
 *                              multiple_iterators=multiple_iterators)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14IteratorRowAll_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14IteratorRowAll_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14IteratorRowAll_2__iter__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorRowAll_2__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1616);

  /* "pysam/calignmentfile.pyx":1617
 * 
 *     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/calignmentfile.pyx":1616
 *                              multiple_iterators=multiple_iterators)
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

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

/* "pysam/calignmentfile.pyx":1619
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_14calignmentfile_14IteratorRowAll_getCurrent(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1619);

  /* "pysam/calignmentfile.pyx":1620
 * 
 *     cdef bam1_t * getCurrent( self ):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1619
 *         return self
 * 
 *     cdef bam1_t * getCurrent( self ):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

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

/* "pysam/calignmentfile.pyx":1622
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,
 */

static int __pyx_f_5pysam_14calignmentfile_14IteratorRowAll_cnext(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1622);

  /* "pysam/calignmentfile.pyx":1624
 *     cdef int cnext(self):
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                          self.samfile.header,
 *                          self.b)
 */
  __pyx_r = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->__pyx_base.samfile->header, __pyx_v_self->__pyx_base.b);
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1622
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator. Used by IteratorColumn'''
 *         return sam_read1(self.htsfile,
 */

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

/* "pysam/calignmentfile.pyx":1628
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14IteratorRowAll_5__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14IteratorRowAll_4__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_14calignmentfile_14IteratorRowAll_4__next__;
#endif
static PyObject *__pyx_pw_5pysam_14calignmentfile_14IteratorRowAll_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14IteratorRowAll_4__next__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorRowAll_4__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1628);

  /* "pysam/calignmentfile.pyx":1633
 *         pyrex uses this non-standard name instead of next()
 *         """
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if (ret >= 0):
 *             return makeAlignedSegment(self.b)
 */
  __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowAll *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);

  /* "pysam/calignmentfile.pyx":1634
 *         """
 *         cdef int ret = self.cnext()
 *         if (ret >= 0):             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b)
 *         elif (ret == -2):
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1635
 *         cdef int ret = self.cnext()
 *         if (ret >= 0):
 *             return makeAlignedSegment(self.b)             # <<<<<<<<<<<<<<
 *         elif (ret == -2):
 *             raise IOError('truncated file')
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_5pysam_14calignmentfile_makeAlignedSegment(__pyx_v_self->__pyx_base.b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":1636
 *         if (ret >= 0):
 *             return makeAlignedSegment(self.b)
 *         elif (ret == -2):             # <<<<<<<<<<<<<<
 *             raise IOError('truncated file')
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_ret == -2) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1637
 *             return makeAlignedSegment(self.b)
 *         elif (ret == -2):
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":1639
 *             raise IOError('truncated file')
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1628
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

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

/* "pysam/calignmentfile.pyx":1653
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                  multiple_iterators=False):
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_18IteratorRowAllRefs_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_18IteratorRowAllRefs_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_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/calignmentfile.pyx":1654
 * 
 *     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);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_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_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_14calignmentfile_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_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.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_14calignmentfile_AlignmentFile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_18IteratorRowAllRefs___init__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *)__pyx_v_self), __pyx_v_samfile, __pyx_v_multiple_iterators);

  /* "pysam/calignmentfile.pyx":1653
 *     """
 * 
 *     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_14calignmentfile_18IteratorRowAllRefs___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1653);

  /* "pysam/calignmentfile.pyx":1656
 *                  multiple_iterators=False):
 * 
 *         IteratorRow.__init__(self, samfile,             # <<<<<<<<<<<<<<
 *                              multiple_iterators=multiple_iterators)
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRow)), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/calignmentfile.pyx":1657
 * 
 *         IteratorRow.__init__(self, samfile,
 *                              multiple_iterators=multiple_iterators)             # <<<<<<<<<<<<<<
 * 
 *         if not samfile._hasIndex():
 */
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_v_multiple_iterators) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":1656
 *                  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_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":1659
 *                              multiple_iterators=multiple_iterators)
 * 
 *         if not samfile._hasIndex():             # <<<<<<<<<<<<<<
 *             raise ValueError("no index available for fetch")
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_hasIndex); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1659; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1659; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = ((!__pyx_t_5) != 0);
  if (__pyx_t_6) {

    /* "pysam/calignmentfile.pyx":1660
 * 
 *         if not samfile._hasIndex():
 *             raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
 * 
 *         self.tid = -1
 */
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1662
 *             raise ValueError("no index available for fetch")
 * 
 *         self.tid = -1             # <<<<<<<<<<<<<<
 * 
 *     def nextiter(self):
 */
  __pyx_v_self->tid = -1;

  /* "pysam/calignmentfile.pyx":1653
 *     """
 * 
 *     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.calignmentfile.IteratorRowAllRefs.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1664
 *         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_14calignmentfile_18IteratorRowAllRefs_3nextiter(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_18IteratorRowAllRefs_2nextiter[] = "IteratorRowAllRefs.nextiter(self)";
static PyObject *__pyx_pw_5pysam_14calignmentfile_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_14calignmentfile_18IteratorRowAllRefs_2nextiter(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_18IteratorRowAllRefs_2nextiter(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  htsFile *__pyx_t_3;
  bam_hdr_t *__pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("nextiter", 0);
  __Pyx_TraceCall("nextiter", __pyx_f[0], 1664);

  /* "pysam/calignmentfile.pyx":1668
 *         # will not be re-opened.
 *         self.rowiter = IteratorRowRegion(self.samfile,
 *                                          self.tid,             # <<<<<<<<<<<<<<
 *                                          0,
 *                                          1<<29)
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/calignmentfile.pyx":1667
 *         # get a new iterator for a chromosome. The file
 *         # will not be re-opened.
 *         self.rowiter = IteratorRowRegion(self.samfile,             # <<<<<<<<<<<<<<
 *                                          self.tid,
 *                                          0,
 */
  __pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->__pyx_base.samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self->__pyx_base.samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->__pyx_base.samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __Pyx_INCREF(__pyx_int_536870912);
  PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_int_536870912);
  __Pyx_GIVEREF(__pyx_int_536870912);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion)), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->rowiter);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->rowiter));
  __pyx_v_self->rowiter = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1673
 *         # 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_3 = __pyx_v_self->__pyx_base.htsfile;
  __pyx_v_self->rowiter->__pyx_base.htsfile = __pyx_t_3;

  /* "pysam/calignmentfile.pyx":1674
 *         # 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_4 = __pyx_v_self->__pyx_base.header;
  __pyx_v_self->rowiter->__pyx_base.header = __pyx_t_4;

  /* "pysam/calignmentfile.pyx":1678
 *         # 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/calignmentfile.pyx":1664
 *         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_AddTraceback("pysam.calignmentfile.IteratorRowAllRefs.nextiter", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1680
 *         self.rowiter.owns_samfile = False
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_18IteratorRowAllRefs_5__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_18IteratorRowAllRefs_5__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_18IteratorRowAllRefs_4__iter__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_18IteratorRowAllRefs_4__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1680);

  /* "pysam/calignmentfile.pyx":1681
 * 
 *     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/calignmentfile.pyx":1680
 *         self.rowiter.owns_samfile = False
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

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

/* "pysam/calignmentfile.pyx":1683
 *         return self
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_18IteratorRowAllRefs_7__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_18IteratorRowAllRefs_6__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_14calignmentfile_18IteratorRowAllRefs_6__next__;
#endif
static PyObject *__pyx_pw_5pysam_14calignmentfile_18IteratorRowAllRefs_7__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_18IteratorRowAllRefs_6__next__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_18IteratorRowAllRefs_6__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1683);

  /* "pysam/calignmentfile.pyx":1689
 *         """
 *         # Create an initial iterator
 *         if self.tid == -1:             # <<<<<<<<<<<<<<
 *             if not self.samfile.nreferences:
 *                 raise StopIteration
 */
  __pyx_t_1 = ((__pyx_v_self->tid == -1) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1690
 *         # Create an initial iterator
 *         if self.tid == -1:
 *             if not self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 raise StopIteration
 *             self.tid = 0
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_3 = ((!__pyx_t_1) != 0);
    if (__pyx_t_3) {

      /* "pysam/calignmentfile.pyx":1691
 *         if self.tid == -1:
 *             if not self.samfile.nreferences:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 *             self.tid = 0
 *             self.nextiter()
 */
      __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/calignmentfile.pyx":1692
 *             if not self.samfile.nreferences:
 *                 raise StopIteration
 *             self.tid = 0             # <<<<<<<<<<<<<<
 *             self.nextiter()
 * 
 */
    __pyx_v_self->tid = 0;

    /* "pysam/calignmentfile.pyx":1693
 *                 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_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && 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);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1693; __pyx_clineno = __LINE__; goto __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;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":1695
 *             self.nextiter()
 * 
 *         while 1:             # <<<<<<<<<<<<<<
 *             self.rowiter.cnext()
 * 
 */
  while (1) {

    /* "pysam/calignmentfile.pyx":1696
 * 
 *         while 1:
 *             self.rowiter.cnext()             # <<<<<<<<<<<<<<
 * 
 *             # If current iterator is not exhausted, return aligned read
 */
    ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_v_self->rowiter->__pyx_vtab)->cnext(__pyx_v_self->rowiter);

    /* "pysam/calignmentfile.pyx":1699
 * 
 *             # If current iterator is not exhausted, return aligned read
 *             if self.rowiter.retval > 0:             # <<<<<<<<<<<<<<
 *                 return makeAlignedSegment(self.rowiter.b)
 * 
 */
    __pyx_t_3 = ((__pyx_v_self->rowiter->__pyx_base.retval > 0) != 0);
    if (__pyx_t_3) {

      /* "pysam/calignmentfile.pyx":1700
 *             # If current iterator is not exhausted, return aligned read
 *             if self.rowiter.retval > 0:
 *                 return makeAlignedSegment(self.rowiter.b)             # <<<<<<<<<<<<<<
 * 
 *             self.tid += 1
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2 = __pyx_f_5pysam_14calignmentfile_makeAlignedSegment(__pyx_v_self->rowiter->__pyx_base.b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      goto __pyx_L0;
    }

    /* "pysam/calignmentfile.pyx":1702
 *                 return makeAlignedSegment(self.rowiter.b)
 * 
 *             self.tid += 1             # <<<<<<<<<<<<<<
 * 
 *             # Otherwise, proceed to next reference or stop
 */
    __pyx_v_self->tid = (__pyx_v_self->tid + 1);

    /* "pysam/calignmentfile.pyx":1705
 * 
 *             # Otherwise, proceed to next reference or stop
 *             if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 self.nextiter()
 *             else:
 */
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_4, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_3) {

      /* "pysam/calignmentfile.pyx":1706
 *             # Otherwise, proceed to next reference or stop
 *             if self.tid < self.samfile.nreferences:
 *                 self.nextiter()             # <<<<<<<<<<<<<<
 *             else:
 *                 raise StopIteration
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nextiter); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && 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);
        }
      }
      if (__pyx_t_2) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else {
        __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1706; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L8;
    }
    /*else*/ {

      /* "pysam/calignmentfile.pyx":1708
 *                 self.nextiter()
 *             else:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L8:;
  }

  /* "pysam/calignmentfile.pyx":1683
 *         return self
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignmentfile.IteratorRowAllRefs.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1721
 *     """
 * 
 *     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_14calignmentfile_20IteratorRowSelection_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_20IteratorRowSelection_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_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);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_positions)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_14calignmentfile_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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.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_14calignmentfile_AlignmentFile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1721; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_20IteratorRowSelection___init__(((struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_20IteratorRowSelection___init__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_positions, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 1721);

  /* "pysam/calignmentfile.pyx":1723
 *     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 *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRow)), __pyx_n_s_init); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":1725
 *         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/calignmentfile.pyx":1726
 * 
 *         self.positions = positions
 *         self.current_pos = 0             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->current_pos = 0;

  /* "pysam/calignmentfile.pyx":1721
 *     """
 * 
 *     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.calignmentfile.IteratorRowSelection.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1728
 *         self.current_pos = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_20IteratorRowSelection_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_20IteratorRowSelection_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_20IteratorRowSelection_2__iter__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_20IteratorRowSelection_2__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1728);

  /* "pysam/calignmentfile.pyx":1729
 * 
 *     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/calignmentfile.pyx":1728
 *         self.current_pos = 0
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

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

/* "pysam/calignmentfile.pyx":1731
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

static bam1_t *__pyx_f_5pysam_14calignmentfile_20IteratorRowSelection_getCurrent(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *__pyx_v_self) {
  bam1_t *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("getCurrent", 0);
  __Pyx_TraceCall("getCurrent", __pyx_f[0], 1731);

  /* "pysam/calignmentfile.pyx":1732
 * 
 *     cdef bam1_t * getCurrent(self):
 *         return self.b             # <<<<<<<<<<<<<<
 * 
 *     cdef int cnext(self):
 */
  __pyx_r = __pyx_v_self->__pyx_base.b;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1731
 *         return self
 * 
 *     cdef bam1_t * getCurrent(self):             # <<<<<<<<<<<<<<
 *         return self.b
 * 
 */

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

/* "pysam/calignmentfile.pyx":1734
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator'''
 * 
 */

static int __pyx_f_5pysam_14calignmentfile_20IteratorRowSelection_cnext(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  int64_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1734);

  /* "pysam/calignmentfile.pyx":1738
 * 
 *         # end iteration if out of positions
 *         if self.current_pos >= len(self.positions): return -1             # <<<<<<<<<<<<<<
 * 
 *         bgzf_seek(hts_get_bgzfp(self.htsfile),
 */
  __pyx_t_1 = __pyx_v_self->positions;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((__pyx_v_self->current_pos >= __pyx_t_2) != 0);
  if (__pyx_t_3) {
    __pyx_r = -1;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":1741
 * 
 *         bgzf_seek(hts_get_bgzfp(self.htsfile),
 *                   self.positions[self.current_pos],             # <<<<<<<<<<<<<<
 *                   0)
 *         self.current_pos += 1
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_self->positions, __pyx_v_self->current_pos, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1741; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_As_int64_t(__pyx_t_1); if (unlikely((__pyx_t_4 == (int64_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1741; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1740
 *         if self.current_pos >= len(self.positions): return -1
 * 
 *         bgzf_seek(hts_get_bgzfp(self.htsfile),             # <<<<<<<<<<<<<<
 *                   self.positions[self.current_pos],
 *                   0)
 */
  bgzf_seek(hts_get_bgzfp(__pyx_v_self->__pyx_base.htsfile), __pyx_t_4, 0);

  /* "pysam/calignmentfile.pyx":1743
 *                   self.positions[self.current_pos],
 *                   0)
 *         self.current_pos += 1             # <<<<<<<<<<<<<<
 *         return sam_read1(self.htsfile,
 *                          self.samfile.header,
 */
  __pyx_v_self->current_pos = (__pyx_v_self->current_pos + 1);

  /* "pysam/calignmentfile.pyx":1744
 *                   0)
 *         self.current_pos += 1
 *         return sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                          self.samfile.header,
 *                          self.b)
 */
  __pyx_r = sam_read1(__pyx_v_self->__pyx_base.htsfile, __pyx_v_self->__pyx_base.samfile->header, __pyx_v_self->__pyx_base.b);
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1734
 *         return self.b
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''cversion of iterator'''
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_WriteUnraisable("pysam.calignmentfile.IteratorRowSelection.cnext", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1748
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_20IteratorRowSelection_5__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_20IteratorRowSelection_4__next__[] = "python version of next().\n\n        pyrex uses this non-standard name instead of next()\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_14calignmentfile_20IteratorRowSelection_4__next__;
#endif
static PyObject *__pyx_pw_5pysam_14calignmentfile_20IteratorRowSelection_5__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_20IteratorRowSelection_4__next__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_20IteratorRowSelection_4__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *__pyx_v_self) {
  int __pyx_v_ret;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 1748);

  /* "pysam/calignmentfile.pyx":1753
 *         pyrex uses this non-standard name instead of next()
 *         """
 *         cdef int ret = self.cnext()             # <<<<<<<<<<<<<<
 *         if (ret >= 0):
 *             return makeAlignedSegment(self.b)
 */
  __pyx_v_ret = ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowSelection *)__pyx_v_self->__pyx_vtab)->cnext(__pyx_v_self);

  /* "pysam/calignmentfile.pyx":1754
 *         """
 *         cdef int ret = self.cnext()
 *         if (ret >= 0):             # <<<<<<<<<<<<<<
 *             return makeAlignedSegment(self.b)
 *         elif (ret == -2):
 */
  __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1755
 *         cdef int ret = self.cnext()
 *         if (ret >= 0):
 *             return makeAlignedSegment(self.b)             # <<<<<<<<<<<<<<
 *         elif (ret == -2):
 *             raise IOError('truncated file')
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_5pysam_14calignmentfile_makeAlignedSegment(__pyx_v_self->__pyx_base.b); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":1756
 *         if (ret >= 0):
 *             return makeAlignedSegment(self.b)
 *         elif (ret == -2):             # <<<<<<<<<<<<<<
 *             raise IOError('truncated file')
 *         else:
 */
  __pyx_t_1 = ((__pyx_v_ret == -2) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1757
 *             return makeAlignedSegment(self.b)
 *         elif (ret == -2):
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IOError, __pyx_tuple__65, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":1759
 *             raise IOError('truncated file')
 *         else:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":1748
 *                          self.b)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 * 
 */

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

/* "pysam/calignmentfile.pyx":1762
 * 
 * 
 * cdef int __advance_nofilter(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance without any read filtering.
 *     '''
 */

static int __pyx_f_5pysam_14calignmentfile___advance_nofilter(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_14calignmentfile___iterdata *__pyx_v_d;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__advance_nofilter", 0);
  __Pyx_TraceCall("__advance_nofilter", __pyx_f[0], 1762);

  /* "pysam/calignmentfile.pyx":1766
 *     '''
 *     cdef __iterdata * d
 *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     return sam_itr_next(d.htsfile, d.iter, b)
 * 
 */
  __pyx_v_d = ((__pyx_t_5pysam_14calignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/calignmentfile.pyx":1767
 *     cdef __iterdata * d
 *     d = <__iterdata*>data
 *     return sam_itr_next(d.htsfile, d.iter, b)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1762
 * 
 * 
 * cdef int __advance_nofilter(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''advance without any read filtering.
 *     '''
 */

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

/* "pysam/calignmentfile.pyx":1770
 * 
 * 
 * cdef int __advance_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''only use reads for pileup passing basic
 *     filters:
 */

static int __pyx_f_5pysam_14calignmentfile___advance_all(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_14calignmentfile___iterdata *__pyx_v_d;
  PyObject *__pyx_v_mask = 0;
  int __pyx_v_ret;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__advance_all", 0);
  __Pyx_TraceCall("__advance_all", __pyx_f[0], 1770);

  /* "pysam/calignmentfile.pyx":1778
 * 
 *     cdef __iterdata * d
 *     cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP             # <<<<<<<<<<<<<<
 *     d = <__iterdata*>data
 *     cdef int ret = sam_itr_next(d.htsfile, d.iter, b)
 */
  __pyx_t_1 = __Pyx_PyInt_From_int((((BAM_FUNMAP | BAM_FSECONDARY) | BAM_FQCFAIL) | BAM_FDUP)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_mask = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1779
 *     cdef __iterdata * d
 *     cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP
 *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
 *     cdef int ret = sam_itr_next(d.htsfile, d.iter, b)
 *     while ret >= 0 and b.core.flag & mask:
 */
  __pyx_v_d = ((__pyx_t_5pysam_14calignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/calignmentfile.pyx":1780
 *     cdef mask = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP
 *     d = <__iterdata*>data
 *     cdef int ret = sam_itr_next(d.htsfile, d.iter, b)             # <<<<<<<<<<<<<<
 *     while ret >= 0 and b.core.flag & mask:
 *         ret = sam_itr_next(d.htsfile, d.iter, b)
 */
  __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);

  /* "pysam/calignmentfile.pyx":1781
 *     d = <__iterdata*>data
 *     cdef int ret = sam_itr_next(d.htsfile, d.iter, b)
 *     while ret >= 0 and b.core.flag & mask:             # <<<<<<<<<<<<<<
 *         ret = sam_itr_next(d.htsfile, d.iter, b)
 * 
 */
  while (1) {
    __pyx_t_3 = ((__pyx_v_ret >= 0) != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_2 = __pyx_t_3;
      goto __pyx_L5_bool_binop_done;
    }
    __pyx_t_1 = __Pyx_PyInt_From_uint16_t(__pyx_v_b->core.flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyNumber_And(__pyx_t_1, __pyx_v_mask); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = __pyx_t_3;
    __pyx_L5_bool_binop_done:;
    if (!__pyx_t_2) break;

    /* "pysam/calignmentfile.pyx":1782
 *     cdef int ret = sam_itr_next(d.htsfile, d.iter, b)
 *     while ret >= 0 and b.core.flag & mask:
 *         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/calignmentfile.pyx":1784
 *         ret = sam_itr_next(d.htsfile, d.iter, b)
 * 
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1770
 * 
 * 
 * cdef int __advance_all(void *data, bam1_t *b):             # <<<<<<<<<<<<<<
 *     '''only use reads for pileup passing basic
 *     filters:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("pysam.calignmentfile.__advance_all", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_mask);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1787
 * 
 * 
 * cdef int __advance_snpcalls(void * data, bam1_t * b):             # <<<<<<<<<<<<<<
 *     '''advance using same filter and read processing as in
 *     the samtools pileup.
 */

static int __pyx_f_5pysam_14calignmentfile___advance_snpcalls(void *__pyx_v_data, bam1_t *__pyx_v_b) {
  __pyx_t_5pysam_14calignmentfile___iterdata *__pyx_v_d;
  int __pyx_v_ret;
  int __pyx_v_skip;
  int __pyx_v_q;
  int __pyx_v_is_cns;
  int __pyx_v_is_nobaq;
  int __pyx_v_capQ_thres;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int32_t __pyx_t_3;
  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_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__advance_snpcalls", 0);
  __Pyx_TraceCall("__advance_snpcalls", __pyx_f[0], 1787);

  /* "pysam/calignmentfile.pyx":1799
 *     # 2. bam_cap_mapQ
 *     cdef __iterdata * d
 *     d = <__iterdata*>data             # <<<<<<<<<<<<<<
 * 
 *     cdef int ret = sam_itr_next(d.htsfile, d.iter, b)
 */
  __pyx_v_d = ((__pyx_t_5pysam_14calignmentfile___iterdata *)__pyx_v_data);

  /* "pysam/calignmentfile.pyx":1801
 *     d = <__iterdata*>data
 * 
 *     cdef int ret = sam_itr_next(d.htsfile, d.iter, b)             # <<<<<<<<<<<<<<
 *     cdef int skip = 0
 *     cdef int q
 */
  __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);

  /* "pysam/calignmentfile.pyx":1802
 * 
 *     cdef int ret = sam_itr_next(d.htsfile, d.iter, b)
 *     cdef int skip = 0             # <<<<<<<<<<<<<<
 *     cdef int q
 *     cdef int is_cns = 1
 */
  __pyx_v_skip = 0;

  /* "pysam/calignmentfile.pyx":1804
 *     cdef int skip = 0
 *     cdef int q
 *     cdef int is_cns = 1             # <<<<<<<<<<<<<<
 *     cdef int is_nobaq = 0
 *     cdef int capQ_thres = 0
 */
  __pyx_v_is_cns = 1;

  /* "pysam/calignmentfile.pyx":1805
 *     cdef int q
 *     cdef int is_cns = 1
 *     cdef int is_nobaq = 0             # <<<<<<<<<<<<<<
 *     cdef int capQ_thres = 0
 * 
 */
  __pyx_v_is_nobaq = 0;

  /* "pysam/calignmentfile.pyx":1806
 *     cdef int is_cns = 1
 *     cdef int is_nobaq = 0
 *     cdef int capQ_thres = 0             # <<<<<<<<<<<<<<
 * 
 *     # reload sequence
 */
  __pyx_v_capQ_thres = 0;

  /* "pysam/calignmentfile.pyx":1809
 * 
 *     # reload sequence
 *     if d.fastafile != NULL and b.core.tid != d.tid:             # <<<<<<<<<<<<<<
 *         if d.seq != NULL:
 *             free(d.seq)
 */
  __pyx_t_2 = ((__pyx_v_d->fastafile != NULL) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = ((__pyx_v_b->core.tid != __pyx_v_d->tid) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":1810
 *     # 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_1 = ((__pyx_v_d->seq != NULL) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":1811
 *     if d.fastafile != NULL and b.core.tid != d.tid:
 *         if d.seq != NULL:
 *             free(d.seq)             # <<<<<<<<<<<<<<
 *         d.tid = b.core.tid
 *         d.seq = faidx_fetch_seq(
 */
      free(__pyx_v_d->seq);
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysam/calignmentfile.pyx":1812
 *         if d.seq != NULL:
 *             free(d.seq)
 *         d.tid = b.core.tid             # <<<<<<<<<<<<<<
 *         d.seq = faidx_fetch_seq(
 *             d.fastafile,
 */
    __pyx_t_3 = __pyx_v_b->core.tid;
    __pyx_v_d->tid = __pyx_t_3;

    /* "pysam/calignmentfile.pyx":1813
 *             free(d.seq)
 *         d.tid = b.core.tid
 *         d.seq = faidx_fetch_seq(             # <<<<<<<<<<<<<<
 *             d.fastafile,
 *             d.header.target_name[d.tid],
 */
    __pyx_v_d->seq = faidx_fetch_seq(__pyx_v_d->fastafile, (__pyx_v_d->header->target_name[__pyx_v_d->tid]), 0, __pyx_v_5pysam_14calignmentfile_max_pos, (&__pyx_v_d->seq_len));

    /* "pysam/calignmentfile.pyx":1819
 *             &d.seq_len)
 * 
 *         if d.seq == NULL:             # <<<<<<<<<<<<<<
 *             raise ValueError(
 *                 "reference sequence for '%s' (tid=%i) not found" % \
 */
    __pyx_t_1 = ((__pyx_v_d->seq == NULL) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":1822
 *             raise ValueError(
 *                 "reference sequence for '%s' (tid=%i) not found" % \
 *                 (d.header.target_name[d.tid],             # <<<<<<<<<<<<<<
 *                  d.tid))
 * 
 */
      __pyx_t_4 = __Pyx_PyBytes_FromString((__pyx_v_d->header->target_name[__pyx_v_d->tid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);

      /* "pysam/calignmentfile.pyx":1823
 *                 "reference sequence for '%s' (tid=%i) not found" % \
 *                 (d.header.target_name[d.tid],
 *                  d.tid))             # <<<<<<<<<<<<<<
 * 
 *     while ret >= 0:
 */
      __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_d->tid); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);

      /* "pysam/calignmentfile.pyx":1822
 *             raise ValueError(
 *                 "reference sequence for '%s' (tid=%i) not found" % \
 *                 (d.header.target_name[d.tid],             # <<<<<<<<<<<<<<
 *                  d.tid))
 * 
 */
      __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_4 = 0;
      __pyx_t_5 = 0;

      /* "pysam/calignmentfile.pyx":1821
 *         if d.seq == NULL:
 *             raise ValueError(
 *                 "reference sequence for '%s' (tid=%i) not found" % \             # <<<<<<<<<<<<<<
 *                 (d.header.target_name[d.tid],
 *                  d.tid))
 */
      __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_reference_sequence_for_s_tid_i_n, __pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "pysam/calignmentfile.pyx":1820
 * 
 *         if d.seq == NULL:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "reference sequence for '%s' (tid=%i) not found" % \
 *                 (d.header.target_name[d.tid],
 */
      __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":1825
 *                  d.tid))
 * 
 *     while ret >= 0:             # <<<<<<<<<<<<<<
 *         skip = 0
 * 
 */
  while (1) {
    __pyx_t_1 = ((__pyx_v_ret >= 0) != 0);
    if (!__pyx_t_1) break;

    /* "pysam/calignmentfile.pyx":1826
 * 
 *     while ret >= 0:
 *         skip = 0             # <<<<<<<<<<<<<<
 * 
 *         # realign read - changes base qualities
 */
    __pyx_v_skip = 0;

    /* "pysam/calignmentfile.pyx":1829
 * 
 *         # realign read - changes base qualities
 *         if d.seq != NULL and is_cns and not is_nobaq:             # <<<<<<<<<<<<<<
 *             bam_prob_realn(b, d.seq)
 * 
 */
    __pyx_t_2 = ((__pyx_v_d->seq != NULL) != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_2 = (__pyx_v_is_cns != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_2 = ((!(__pyx_v_is_nobaq != 0)) != 0);
    __pyx_t_1 = __pyx_t_2;
    __pyx_L11_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":1830
 *         # realign read - changes base qualities
 *         if d.seq != NULL and is_cns and not is_nobaq:
 *             bam_prob_realn(b, d.seq)             # <<<<<<<<<<<<<<
 * 
 *         if d.seq != NULL and capQ_thres > 10:
 */
      bam_prob_realn(__pyx_v_b, __pyx_v_d->seq);
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "pysam/calignmentfile.pyx":1832
 *             bam_prob_realn(b, d.seq)
 * 
 *         if d.seq != NULL and capQ_thres > 10:             # <<<<<<<<<<<<<<
 *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
 *             if q < 0:
 */
    __pyx_t_2 = ((__pyx_v_d->seq != NULL) != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L15_bool_binop_done;
    }
    __pyx_t_2 = ((__pyx_v_capQ_thres > 10) != 0);
    __pyx_t_1 = __pyx_t_2;
    __pyx_L15_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":1833
 * 
 *         if d.seq != NULL and capQ_thres > 10:
 *             q = bam_cap_mapQ(b, d.seq, capQ_thres)             # <<<<<<<<<<<<<<
 *             if q < 0:
 *                 skip = 1
 */
      __pyx_v_q = bam_cap_mapQ(__pyx_v_b, __pyx_v_d->seq, __pyx_v_capQ_thres);

      /* "pysam/calignmentfile.pyx":1834
 *         if d.seq != NULL and capQ_thres > 10:
 *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
 *             if q < 0:             # <<<<<<<<<<<<<<
 *                 skip = 1
 *             elif b.core.qual > q:
 */
      __pyx_t_1 = ((__pyx_v_q < 0) != 0);
      if (__pyx_t_1) {

        /* "pysam/calignmentfile.pyx":1835
 *             q = bam_cap_mapQ(b, d.seq, capQ_thres)
 *             if q < 0:
 *                 skip = 1             # <<<<<<<<<<<<<<
 *             elif b.core.qual > q:
 *                 b.core.qual = q
 */
        __pyx_v_skip = 1;
        goto __pyx_L17;
      }

      /* "pysam/calignmentfile.pyx":1836
 *             if q < 0:
 *                 skip = 1
 *             elif b.core.qual > q:             # <<<<<<<<<<<<<<
 *                 b.core.qual = q
 *         if b.core.flag & BAM_FUNMAP:
 */
      __pyx_t_1 = ((__pyx_v_b->core.qual > __pyx_v_q) != 0);
      if (__pyx_t_1) {

        /* "pysam/calignmentfile.pyx":1837
 *                 skip = 1
 *             elif b.core.qual > q:
 *                 b.core.qual = q             # <<<<<<<<<<<<<<
 *         if b.core.flag & BAM_FUNMAP:
 *             skip = 1
 */
        __pyx_v_b->core.qual = __pyx_v_q;
        goto __pyx_L17;
      }
      __pyx_L17:;
      goto __pyx_L14;
    }
    __pyx_L14:;

    /* "pysam/calignmentfile.pyx":1838
 *             elif b.core.qual > q:
 *                 b.core.qual = q
 *         if b.core.flag & BAM_FUNMAP:             # <<<<<<<<<<<<<<
 *             skip = 1
 *         elif b.core.flag & 1 and not b.core.flag & 2:
 */
    __pyx_t_1 = ((__pyx_v_b->core.flag & BAM_FUNMAP) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":1839
 *                 b.core.qual = q
 *         if b.core.flag & BAM_FUNMAP:
 *             skip = 1             # <<<<<<<<<<<<<<
 *         elif b.core.flag & 1 and not b.core.flag & 2:
 *             skip = 1
 */
      __pyx_v_skip = 1;
      goto __pyx_L18;
    }

    /* "pysam/calignmentfile.pyx":1840
 *         if b.core.flag & BAM_FUNMAP:
 *             skip = 1
 *         elif b.core.flag & 1 and not b.core.flag & 2:             # <<<<<<<<<<<<<<
 *             skip = 1
 * 
 */
    __pyx_t_2 = ((__pyx_v_b->core.flag & 1) != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L19_bool_binop_done;
    }
    __pyx_t_2 = ((!((__pyx_v_b->core.flag & 2) != 0)) != 0);
    __pyx_t_1 = __pyx_t_2;
    __pyx_L19_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":1841
 *             skip = 1
 *         elif b.core.flag & 1 and not b.core.flag & 2:
 *             skip = 1             # <<<<<<<<<<<<<<
 * 
 *         if not skip:
 */
      __pyx_v_skip = 1;
      goto __pyx_L18;
    }
    __pyx_L18:;

    /* "pysam/calignmentfile.pyx":1843
 *             skip = 1
 * 
 *         if not skip:             # <<<<<<<<<<<<<<
 *             break
 *         # additional filters
 */
    __pyx_t_1 = ((!(__pyx_v_skip != 0)) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":1844
 * 
 *         if not skip:
 *             break             # <<<<<<<<<<<<<<
 *         # additional filters
 * 
 */
      goto __pyx_L9_break;
    }

    /* "pysam/calignmentfile.pyx":1847
 *         # additional filters
 * 
 *         ret = sam_itr_next(d.htsfile, d.iter, b)             # <<<<<<<<<<<<<<
 * 
 *     return ret
 */
    __pyx_v_ret = sam_itr_next(__pyx_v_d->htsfile, __pyx_v_d->iter, __pyx_v_b);
  }
  __pyx_L9_break:;

  /* "pysam/calignmentfile.pyx":1849
 *         ret = sam_itr_next(d.htsfile, d.iter, b)
 * 
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * cdef class IteratorColumn:
 */
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1787
 * 
 * 
 * cdef int __advance_snpcalls(void * data, bam1_t * b):             # <<<<<<<<<<<<<<
 *     '''advance using same filter and read processing as in
 *     the samtools pileup.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_WriteUnraisable("pysam.calignmentfile.__advance_snpcalls", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1897
 *     '''
 * 
 *     def __cinit__( self, AlignmentFile samfile, **kwargs ):             # <<<<<<<<<<<<<<
 *         self.samfile = samfile
 *         # TODO
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14IteratorColumn_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14IteratorColumn_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_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);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1897; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_14calignmentfile_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_filename = __pyx_f[0]; __pyx_lineno = 1897; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.calignmentfile.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_14calignmentfile_AlignmentFile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1897; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14IteratorColumn___cinit__(((struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_14IteratorColumn___cinit__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 1897);

  /* "pysam/calignmentfile.pyx":1898
 * 
 *     def __cinit__( self, AlignmentFile samfile, **kwargs ):
 *         self.samfile = samfile             # <<<<<<<<<<<<<<
 *         # TODO
 *         # self.mask = kwargs.get("mask", BAM_DEF_MASK )
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GOTREF(__pyx_v_self->samfile);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
  __pyx_v_self->samfile = __pyx_v_samfile;

  /* "pysam/calignmentfile.pyx":1901
 *         # TODO
 *         # self.mask = kwargs.get("mask", BAM_DEF_MASK )
 *         self.fastafile = kwargs.get("fastafile", None)             # <<<<<<<<<<<<<<
 *         self.stepper = kwargs.get("stepper", None)
 *         self.max_depth = kwargs.get("max_depth", 8000)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_fastafile, Py_None); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5pysam_6cfaidx_Fastafile))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->fastafile);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->fastafile));
  __pyx_v_self->fastafile = ((struct __pyx_obj_5pysam_6cfaidx_Fastafile *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1902
 *         # self.mask = kwargs.get("mask", BAM_DEF_MASK )
 *         self.fastafile = kwargs.get("fastafile", None)
 *         self.stepper = kwargs.get("stepper", None)             # <<<<<<<<<<<<<<
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.iterdata.seq = NULL
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_stepper, Py_None); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1902; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->stepper);
  __Pyx_DECREF(__pyx_v_self->stepper);
  __pyx_v_self->stepper = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1903
 *         self.fastafile = kwargs.get("fastafile", None)
 *         self.stepper = kwargs.get("stepper", None)
 *         self.max_depth = kwargs.get("max_depth", 8000)             # <<<<<<<<<<<<<<
 *         self.iterdata.seq = NULL
 *         self.tid = 0
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_kwargs, __pyx_n_s_max_depth, __pyx_int_8000); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_self->max_depth = __pyx_t_2;

  /* "pysam/calignmentfile.pyx":1904
 *         self.stepper = kwargs.get("stepper", None)
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *         self.tid = 0
 *         self.pos = 0
 */
  __pyx_v_self->iterdata.seq = NULL;

  /* "pysam/calignmentfile.pyx":1905
 *         self.max_depth = kwargs.get("max_depth", 8000)
 *         self.iterdata.seq = NULL
 *         self.tid = 0             # <<<<<<<<<<<<<<
 *         self.pos = 0
 *         self.n_plp = 0
 */
  __pyx_v_self->tid = 0;

  /* "pysam/calignmentfile.pyx":1906
 *         self.iterdata.seq = NULL
 *         self.tid = 0
 *         self.pos = 0             # <<<<<<<<<<<<<<
 *         self.n_plp = 0
 *         self.plp = NULL
 */
  __pyx_v_self->pos = 0;

  /* "pysam/calignmentfile.pyx":1907
 *         self.tid = 0
 *         self.pos = 0
 *         self.n_plp = 0             # <<<<<<<<<<<<<<
 *         self.plp = NULL
 *         self.pileup_iter = <bam_plp_t>NULL
 */
  __pyx_v_self->n_plp = 0;

  /* "pysam/calignmentfile.pyx":1908
 *         self.pos = 0
 *         self.n_plp = 0
 *         self.plp = NULL             # <<<<<<<<<<<<<<
 *         self.pileup_iter = <bam_plp_t>NULL
 * 
 */
  __pyx_v_self->plp = NULL;

  /* "pysam/calignmentfile.pyx":1909
 *         self.n_plp = 0
 *         self.plp = NULL
 *         self.pileup_iter = <bam_plp_t>NULL             # <<<<<<<<<<<<<<
 * 
 *     def __iter__(self):
 */
  __pyx_v_self->pileup_iter = ((bam_plp_t)NULL);

  /* "pysam/calignmentfile.pyx":1897
 *     '''
 * 
 *     def __cinit__( self, AlignmentFile samfile, **kwargs ):             # <<<<<<<<<<<<<<
 *         self.samfile = samfile
 *         # TODO
 */

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

/* "pysam/calignmentfile.pyx":1911
 *         self.pileup_iter = <bam_plp_t>NULL
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14IteratorColumn_3__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14IteratorColumn_3__iter__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14IteratorColumn_2__iter__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorColumn_2__iter__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__iter__", 0);
  __Pyx_TraceCall("__iter__", __pyx_f[0], 1911);

  /* "pysam/calignmentfile.pyx":1912
 * 
 *     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/calignmentfile.pyx":1911
 *         self.pileup_iter = <bam_plp_t>NULL
 * 
 *     def __iter__(self):             # <<<<<<<<<<<<<<
 *         return self
 * 
 */

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

/* "pysam/calignmentfile.pyx":1914
 *         return self
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''perform next iteration.
 *         '''
 */

static int __pyx_f_5pysam_14calignmentfile_14IteratorColumn_cnext(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("cnext", 0);
  __Pyx_TraceCall("cnext", __pyx_f[0], 1914);

  /* "pysam/calignmentfile.pyx":1917
 *         '''perform next iteration.
 *         '''
 *         self.plp = bam_plp_auto( self.pileup_iter,             # <<<<<<<<<<<<<<
 *                                  &self.tid,
 *                                  &self.pos,
 */
  __pyx_v_self->plp = bam_plp_auto(__pyx_v_self->pileup_iter, (&__pyx_v_self->tid), (&__pyx_v_self->pos), (&__pyx_v_self->n_plp));

  /* "pysam/calignmentfile.pyx":1914
 *         return self
 * 
 *     cdef int cnext(self):             # <<<<<<<<<<<<<<
 *         '''perform next iteration.
 *         '''
 */

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

/* "pysam/calignmentfile.pyx":1922
 *                                  &self.n_plp )
 * 
 *     cdef char * getSequence( self ):             # <<<<<<<<<<<<<<
 *         '''return current reference sequence underlying the iterator.
 *         '''
 */

static char *__pyx_f_5pysam_14calignmentfile_14IteratorColumn_getSequence(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self) {
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("getSequence", 0);
  __Pyx_TraceCall("getSequence", __pyx_f[0], 1922);

  /* "pysam/calignmentfile.pyx":1925
 *         '''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/calignmentfile.pyx":1922
 *                                  &self.n_plp )
 * 
 *     cdef char * getSequence( self ):             # <<<<<<<<<<<<<<
 *         '''return current reference sequence underlying the iterator.
 *         '''
 */

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

/* "pysam/calignmentfile.pyx":1929
 *     property seq_len:
 *         '''current sequence length.'''
 *         def __get__(self): return self.iterdata.seq_len             # <<<<<<<<<<<<<<
 * 
 *     def addReference(self, Fastafile fastafile):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14IteratorColumn_7seq_len_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_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_14calignmentfile_14IteratorColumn_7seq_len___get__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorColumn_7seq_len___get__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 1929);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->iterdata.seq_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":1931
 *         def __get__(self): return self.iterdata.seq_len
 * 
 *     def addReference(self, Fastafile fastafile):             # <<<<<<<<<<<<<<
 *        '''
 *        add reference sequences in *fastafile* to iterator.'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14IteratorColumn_5addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14IteratorColumn_4addReference[] = "IteratorColumn.addReference(self, Fastafile fastafile)\n\n       add reference sequences in *fastafile* to iterator.";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14IteratorColumn_5addReference(PyObject *__pyx_v_self, PyObject *__pyx_v_fastafile) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("addReference (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fastafile), __pyx_ptype_5pysam_6cfaidx_Fastafile, 1, "fastafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1931; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14IteratorColumn_4addReference(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self), ((struct __pyx_obj_5pysam_6cfaidx_Fastafile *)__pyx_v_fastafile));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorColumn_4addReference(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self, struct __pyx_obj_5pysam_6cfaidx_Fastafile *__pyx_v_fastafile) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  faidx_t *__pyx_t_2;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("addReference", 0);
  __Pyx_TraceCall("addReference", __pyx_f[0], 1931);

  /* "pysam/calignmentfile.pyx":1934
 *        '''
 *        add reference sequences in *fastafile* to iterator.'''
 *        self.fastafile = fastafile             # <<<<<<<<<<<<<<
 *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
 *        self.iterdata.tid = -1
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_fastafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fastafile));
  __Pyx_GOTREF(__pyx_v_self->fastafile);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->fastafile));
  __pyx_v_self->fastafile = __pyx_v_fastafile;

  /* "pysam/calignmentfile.pyx":1935
 *        add reference sequences in *fastafile* to iterator.'''
 *        self.fastafile = fastafile
 *        if self.iterdata.seq != NULL: free(self.iterdata.seq)             # <<<<<<<<<<<<<<
 *        self.iterdata.tid = -1
 *        self.iterdata.fastafile = self.fastafile.fastafile
 */
  __pyx_t_1 = ((__pyx_v_self->iterdata.seq != NULL) != 0);
  if (__pyx_t_1) {
    free(__pyx_v_self->iterdata.seq);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":1936
 *        self.fastafile = fastafile
 *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
 *        self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 */
  __pyx_v_self->iterdata.tid = -1;

  /* "pysam/calignmentfile.pyx":1937
 *        if self.iterdata.seq != NULL: free(self.iterdata.seq)
 *        self.iterdata.tid = -1
 *        self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
 * 
 *     def hasReference(self):
 */
  __pyx_t_2 = __pyx_v_self->fastafile->__pyx_base.fastafile;
  __pyx_v_self->iterdata.fastafile = __pyx_t_2;

  /* "pysam/calignmentfile.pyx":1931
 *         def __get__(self): return self.iterdata.seq_len
 * 
 *     def addReference(self, Fastafile fastafile):             # <<<<<<<<<<<<<<
 *        '''
 *        add reference sequences in *fastafile* to iterator.'''
 */

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

/* "pysam/calignmentfile.pyx":1939
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 *     def hasReference(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return true if iterator is associated with a reference'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14IteratorColumn_7hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14IteratorColumn_6hasReference[] = "IteratorColumn.hasReference(self)\n\n        return true if iterator is associated with a reference";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14IteratorColumn_7hasReference(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("hasReference (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14IteratorColumn_6hasReference(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14IteratorColumn_6hasReference(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("hasReference", 0);
  __Pyx_TraceCall("hasReference", __pyx_f[0], 1939);

  /* "pysam/calignmentfile.pyx":1942
 *         '''
 *         return true if iterator is associated with a reference'''
 *         return self.fastafile             # <<<<<<<<<<<<<<
 * 
 *     cdef setMask(self, mask):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->fastafile));
  __pyx_r = ((PyObject *)__pyx_v_self->fastafile);
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":1939
 *        self.iterdata.fastafile = self.fastafile.fastafile
 * 
 *     def hasReference(self):             # <<<<<<<<<<<<<<
 *         '''
 *         return true if iterator is associated with a reference'''
 */

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

/* "pysam/calignmentfile.pyx":1944
 *         return self.fastafile
 * 
 *     cdef setMask(self, mask):             # <<<<<<<<<<<<<<
 *         '''set masking flag in iterator.
 * 
 */

static PyObject *__pyx_f_5pysam_14calignmentfile_14IteratorColumn_setMask(CYTHON_UNUSED struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_mask) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("setMask", 0);
  __Pyx_TraceCall("setMask", __pyx_f[0], 1944);

  /* "pysam/calignmentfile.pyx":1949
 *         reads with bits set in *mask* will be skipped.
 *         '''
 *         raise NotImplementedError()             # <<<<<<<<<<<<<<
 *         # self.mask = mask
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 */
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_builtin_NotImplementedError); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":1944
 *         return self.fastafile
 * 
 *     cdef setMask(self, mask):             # <<<<<<<<<<<<<<
 *         '''set masking flag in iterator.
 * 
 */

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

/* "pysam/calignmentfile.pyx":1953
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 * 
 *     cdef setupIteratorData( self,             # <<<<<<<<<<<<<<
 *                             int tid,
 *                             int start,
 */

static PyObject *__pyx_f_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData *__pyx_optional_args) {
  int __pyx_v_multiple_iterators = ((int)0);
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  htsFile *__pyx_t_6;
  hts_itr_t *__pyx_t_7;
  bam_hdr_t *__pyx_t_8;
  int __pyx_t_9;
  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_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("setupIteratorData", 0);
  __Pyx_TraceCall("setupIteratorData", __pyx_f[0], 1953);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_multiple_iterators = __pyx_optional_args->multiple_iterators;
    }
  }

  /* "pysam/calignmentfile.pyx":1960
 *         '''setup the iterator structure'''
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, end, 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_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_start); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_end); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_self->samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion)), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_GIVEREF(__pyx_t_4);
  __Pyx_GOTREF(__pyx_v_self->iter);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->iter));
  __pyx_v_self->iter = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":1961
 * 
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, end, 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->htsfile;
  __pyx_v_self->iterdata.htsfile = __pyx_t_6;

  /* "pysam/calignmentfile.pyx":1962
 *         self.iter = IteratorRowRegion(self.samfile, tid, start, end, 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/calignmentfile.pyx":1963
 *         self.iterdata.htsfile = self.samfile.htsfile
 *         self.iterdata.iter = self.iter.iter
 *         self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *         self.iterdata.tid = -1
 *         self.iterdata.header = self.samfile.header
 */
  __pyx_v_self->iterdata.seq = NULL;

  /* "pysam/calignmentfile.pyx":1964
 *         self.iterdata.iter = self.iter.iter
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 *         self.iterdata.header = self.samfile.header
 * 
 */
  __pyx_v_self->iterdata.tid = -1;

  /* "pysam/calignmentfile.pyx":1965
 *         self.iterdata.seq = NULL
 *         self.iterdata.tid = -1
 *         self.iterdata.header = self.samfile.header             # <<<<<<<<<<<<<<
 * 
 *         if self.fastafile is not None:
 */
  __pyx_t_8 = __pyx_v_self->samfile->header;
  __pyx_v_self->iterdata.header = __pyx_t_8;

  /* "pysam/calignmentfile.pyx":1967
 *         self.iterdata.header = self.samfile.header
 * 
 *         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/calignmentfile.pyx":1968
 * 
 *         if self.fastafile is not None:
 *             self.iterdata.fastafile = self.fastafile.fastafile             # <<<<<<<<<<<<<<
 *         else:
 *             self.iterdata.fastafile = NULL
 */
    __pyx_t_11 = __pyx_v_self->fastafile->__pyx_base.fastafile;
    __pyx_v_self->iterdata.fastafile = __pyx_t_11;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":1970
 *             self.iterdata.fastafile = self.fastafile.fastafile
 *         else:
 *             self.iterdata.fastafile = NULL             # <<<<<<<<<<<<<<
 * 
 *         # Free any previously allocated memory before reassigning
 */
    __pyx_v_self->iterdata.fastafile = NULL;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":1974
 *         # Free any previously allocated memory before reassigning
 *         # pileup_iter
 *         self._free_pileup_iter()             # <<<<<<<<<<<<<<
 * 
 *         if self.stepper is None or self.stepper == "all":
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1974; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":1976
 *         self._free_pileup_iter()
 * 
 *         if self.stepper is None or self.stepper == "all":             # <<<<<<<<<<<<<<
 *             self.pileup_iter = bam_plp_init(
 *                 <bam_plp_auto_f>&__advance_all,
 */
  __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_filename = __pyx_f[0]; __pyx_lineno = 1976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_10 = __pyx_t_12;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_10) {

    /* "pysam/calignmentfile.pyx":1977
 * 
 *         if self.stepper is None or self.stepper == "all":
 *             self.pileup_iter = bam_plp_init(             # <<<<<<<<<<<<<<
 *                 <bam_plp_auto_f>&__advance_all,
 *                 &self.iterdata)
 */
    __pyx_v_self->pileup_iter = bam_plp_init(((bam_plp_auto_f)(&__pyx_f_5pysam_14calignmentfile___advance_all)), (&__pyx_v_self->iterdata));
    goto __pyx_L4;
  }

  /* "pysam/calignmentfile.pyx":1980
 *                 <bam_plp_auto_f>&__advance_all,
 *                 &self.iterdata)
 *         elif self.stepper == "nofilter":             # <<<<<<<<<<<<<<
 *             self.pileup_iter = bam_plp_init(
 *                 <bam_plp_auto_f>&__advance_nofilter,
 */
  __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_nofilter, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_10) {

    /* "pysam/calignmentfile.pyx":1981
 *                 &self.iterdata)
 *         elif self.stepper == "nofilter":
 *             self.pileup_iter = bam_plp_init(             # <<<<<<<<<<<<<<
 *                 <bam_plp_auto_f>&__advance_nofilter,
 *                 &self.iterdata)
 */
    __pyx_v_self->pileup_iter = bam_plp_init(((bam_plp_auto_f)(&__pyx_f_5pysam_14calignmentfile___advance_nofilter)), (&__pyx_v_self->iterdata));
    goto __pyx_L4;
  }

  /* "pysam/calignmentfile.pyx":1984
 *                 <bam_plp_auto_f>&__advance_nofilter,
 *                 &self.iterdata)
 *         elif self.stepper == "samtools":             # <<<<<<<<<<<<<<
 *             self.pileup_iter = bam_plp_init(
 *                 <bam_plp_auto_f>&__advance_snpcalls,
 */
  __pyx_t_10 = (__Pyx_PyString_Equals(__pyx_v_self->stepper, __pyx_n_s_samtools, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1984; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_10) {

    /* "pysam/calignmentfile.pyx":1985
 *                 &self.iterdata)
 *         elif self.stepper == "samtools":
 *             self.pileup_iter = bam_plp_init(             # <<<<<<<<<<<<<<
 *                 <bam_plp_auto_f>&__advance_snpcalls,
 *                 &self.iterdata)
 */
    __pyx_v_self->pileup_iter = bam_plp_init(((bam_plp_auto_f)(&__pyx_f_5pysam_14calignmentfile___advance_snpcalls)), (&__pyx_v_self->iterdata));
    goto __pyx_L4;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":1990
 *         else:
 *             raise ValueError(
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)             # <<<<<<<<<<<<<<
 * 
 *         if self.max_depth:
 */
    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_unknown_stepper_option_s_in_Iter, __pyx_v_self->stepper); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);

    /* "pysam/calignmentfile.pyx":1989
 *                 &self.iterdata)
 *         else:
 *             raise ValueError(             # <<<<<<<<<<<<<<
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 */
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_4, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L4:;

  /* "pysam/calignmentfile.pyx":1992
 *                 "unknown stepper option `%s` in IteratorColumn" % self.stepper)
 * 
 *         if self.max_depth:             # <<<<<<<<<<<<<<
 *             bam_plp_set_maxcnt(self.pileup_iter, self.max_depth)
 * 
 */
  __pyx_t_10 = (__pyx_v_self->max_depth != 0);
  if (__pyx_t_10) {

    /* "pysam/calignmentfile.pyx":1993
 * 
 *         if self.max_depth:
 *             bam_plp_set_maxcnt(self.pileup_iter, self.max_depth)             # <<<<<<<<<<<<<<
 * 
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 */
    bam_plp_set_maxcnt(__pyx_v_self->pileup_iter, __pyx_v_self->max_depth);
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "pysam/calignmentfile.pyx":1953
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 * 
 *     cdef setupIteratorData( self,             # <<<<<<<<<<<<<<
 *                             int tid,
 *                             int start,
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignmentfile.IteratorColumn.setupIteratorData", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":1997
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 * 
 *     cdef reset( self, tid, start, end ):             # <<<<<<<<<<<<<<
 *         '''reset iterator position.
 * 
 */

static PyObject *__pyx_f_5pysam_14calignmentfile_14IteratorColumn_reset(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self, PyObject *__pyx_v_tid, PyObject *__pyx_v_start, PyObject *__pyx_v_end) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  hts_itr_t *__pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("reset", 0);
  __Pyx_TraceCall("reset", __pyx_f[0], 1997);

  /* "pysam/calignmentfile.pyx":2003
 *         having to incur the full set-up costs.
 *         '''
 *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, multiple_iterators = 0 )             # <<<<<<<<<<<<<<
 *         self.iterdata.iter = self.iter.iter
 * 
 */
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2003; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self->samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
  __Pyx_INCREF(__pyx_v_tid);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_tid);
  __Pyx_GIVEREF(__pyx_v_tid);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_end);
  __Pyx_GIVEREF(__pyx_v_end);
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2003; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_multiple_iterators, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2003; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion)), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2003; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __Pyx_GOTREF(__pyx_v_self->iter);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->iter));
  __pyx_v_self->iter = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignmentfile.pyx":2004
 *         '''
 *         self.iter = IteratorRowRegion( self.samfile, tid, start, end, multiple_iterators = 0 )
 *         self.iterdata.iter = self.iter.iter             # <<<<<<<<<<<<<<
 * 
 *         # invalidate sequence if different tid
 */
  __pyx_t_4 = __pyx_v_self->iter->iter;
  __pyx_v_self->iterdata.iter = __pyx_t_4;

  /* "pysam/calignmentfile.pyx":2007
 * 
 *         # invalidate sequence if different tid
 *         if self.tid != tid:             # <<<<<<<<<<<<<<
 *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
 *             self.iterdata.seq = NULL
 */
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_v_tid, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":2008
 *         # invalidate sequence if different tid
 *         if self.tid != tid:
 *             if self.iterdata.seq != NULL: free( self.iterdata.seq )             # <<<<<<<<<<<<<<
 *             self.iterdata.seq = NULL
 *             self.iterdata.tid = -1
 */
    __pyx_t_5 = ((__pyx_v_self->iterdata.seq != NULL) != 0);
    if (__pyx_t_5) {
      free(__pyx_v_self->iterdata.seq);
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "pysam/calignmentfile.pyx":2009
 *         if self.tid != tid:
 *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
 *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 *             self.iterdata.tid = -1
 * 
 */
    __pyx_v_self->iterdata.seq = NULL;

    /* "pysam/calignmentfile.pyx":2010
 *             if self.iterdata.seq != NULL: free( self.iterdata.seq )
 *             self.iterdata.seq = NULL
 *             self.iterdata.tid = -1             # <<<<<<<<<<<<<<
 * 
 *         # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata )
 */
    __pyx_v_self->iterdata.tid = -1;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":2013
 * 
 *         # self.pileup_iter = bam_plp_init( &__advancepileup, &self.iterdata )
 *         bam_plp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
 * 
 *     cdef _free_pileup_iter(self):
 */
  bam_plp_reset(__pyx_v_self->pileup_iter);

  /* "pysam/calignmentfile.pyx":1997
 *         # bam_plp_set_mask( self.pileup_iter, self.mask )
 * 
 *     cdef reset( self, tid, start, end ):             # <<<<<<<<<<<<<<
 *         '''reset iterator position.
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.IteratorColumn.reset", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2015
 *         bam_plp_reset(self.pileup_iter)
 * 
 *     cdef _free_pileup_iter(self):             # <<<<<<<<<<<<<<
 *         '''free the memory alloc'd by bam_plp_init.
 * 
 */

static PyObject *__pyx_f_5pysam_14calignmentfile_14IteratorColumn__free_pileup_iter(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_free_pileup_iter", 0);
  __Pyx_TraceCall("_free_pileup_iter", __pyx_f[0], 2015);

  /* "pysam/calignmentfile.pyx":2021
 *         another pileup_iter, or else memory will be lost.
 *         '''
 *         if self.pileup_iter != <bam_plp_t>NULL:             # <<<<<<<<<<<<<<
 *             bam_plp_reset(self.pileup_iter)
 *             bam_plp_destroy(self.pileup_iter)
 */
  __pyx_t_1 = ((__pyx_v_self->pileup_iter != ((bam_plp_t)NULL)) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":2022
 *         '''
 *         if self.pileup_iter != <bam_plp_t>NULL:
 *             bam_plp_reset(self.pileup_iter)             # <<<<<<<<<<<<<<
 *             bam_plp_destroy(self.pileup_iter)
 *             self.pileup_iter = <bam_plp_t>NULL
 */
    bam_plp_reset(__pyx_v_self->pileup_iter);

    /* "pysam/calignmentfile.pyx":2023
 *         if self.pileup_iter != <bam_plp_t>NULL:
 *             bam_plp_reset(self.pileup_iter)
 *             bam_plp_destroy(self.pileup_iter)             # <<<<<<<<<<<<<<
 *             self.pileup_iter = <bam_plp_t>NULL
 * 
 */
    bam_plp_destroy(__pyx_v_self->pileup_iter);

    /* "pysam/calignmentfile.pyx":2024
 *             bam_plp_reset(self.pileup_iter)
 *             bam_plp_destroy(self.pileup_iter)
 *             self.pileup_iter = <bam_plp_t>NULL             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    __pyx_v_self->pileup_iter = ((bam_plp_t)NULL);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":2015
 *         bam_plp_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);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2026
 *             self.pileup_iter = <bam_plp_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_14calignmentfile_14IteratorColumn_9__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_14calignmentfile_14IteratorColumn_9__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_14calignmentfile_14IteratorColumn_8__dealloc__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2029
 *         # reset in order to avoid memory leak messages for iterators
 *         # that have not been fully consumed
 *         self._free_pileup_iter()             # <<<<<<<<<<<<<<
 *         self.plp = <bam_pileup1_t*>NULL
 * 
 */
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self->__pyx_vtab)->_free_pileup_iter(__pyx_v_self); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":2030
 *         # that have not been fully consumed
 *         self._free_pileup_iter()
 *         self.plp = <bam_pileup1_t*>NULL             # <<<<<<<<<<<<<<
 * 
 *         if self.iterdata.seq != NULL:
 */
  __pyx_v_self->plp = ((bam_pileup1_t *)NULL);

  /* "pysam/calignmentfile.pyx":2032
 *         self.plp = <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/calignmentfile.pyx":2033
 * 
 *         if self.iterdata.seq != NULL:
 *             free(self.iterdata.seq)             # <<<<<<<<<<<<<<
 *             self.iterdata.seq = NULL
 * 
 */
    free(__pyx_v_self->iterdata.seq);

    /* "pysam/calignmentfile.pyx":2034
 *         if self.iterdata.seq != NULL:
 *             free(self.iterdata.seq)
 *             self.iterdata.seq = NULL             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_v_self->iterdata.seq = NULL;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":2026
 *             self.pileup_iter = <bam_plp_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.calignmentfile.IteratorColumn.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "pysam/calignmentfile.pyx":2040
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                   int tid = 0,
 *                   int start = 0,
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_20IteratorColumnRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_20IteratorColumnRegion_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile = 0;
  int __pyx_v_tid;
  int __pyx_v_start;
  int __pyx_v_end;
  int __pyx_v_truncate;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
  __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
  __Pyx_GOTREF(__pyx_v_kwargs);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_samfile,&__pyx_n_s_tid,&__pyx_n_s_start,&__pyx_n_s_end,&__pyx_n_s_truncate,0};
    PyObject* values[5] = {0,0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tid);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_truncate);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_14calignmentfile_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_filename = __pyx_f[0]; __pyx_lineno = 2041; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_tid = ((int)0);
    }
    if (values[2]) {
      __pyx_v_start = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_start == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2042; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_start = ((int)0);
    }
    if (values[3]) {
      __pyx_v_end = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_end == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {
      __pyx_v_end = __pyx_k__66;
    }
    if (values[4]) {
      __pyx_v_truncate = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_truncate == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2044; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysam/calignmentfile.pyx":2044
 *                   int start = 0,
 *                   int end = max_pos,
 *                   int truncate = False,             # <<<<<<<<<<<<<<
 *                   **kwargs ):
 * 
 */
      __pyx_v_truncate = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.calignmentfile.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_14calignmentfile_AlignmentFile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_20IteratorColumnRegion___cinit__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion *)__pyx_v_self), __pyx_v_samfile, __pyx_v_tid, __pyx_v_start, __pyx_v_end, __pyx_v_truncate, __pyx_v_kwargs);

  /* "pysam/calignmentfile.pyx":2040
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                   int tid = 0,
 *                   int start = 0,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_20IteratorColumnRegion___cinit__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion *__pyx_v_self, CYTHON_UNUSED struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_tid, int __pyx_v_start, int __pyx_v_end, int __pyx_v_truncate, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2040);

  /* "pysam/calignmentfile.pyx":2048
 * 
 *         # initialize iterator
 *         self.setupIteratorData( tid, start, end, 1 )             # <<<<<<<<<<<<<<
 *         self.start = start
 *         self.end = end
 */
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.multiple_iterators = 1;
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_tid, __pyx_v_start, __pyx_v_end, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":2049
 *         # initialize iterator
 *         self.setupIteratorData( tid, start, end, 1 )
 *         self.start = start             # <<<<<<<<<<<<<<
 *         self.end = end
 *         self.truncate = truncate
 */
  __pyx_v_self->start = __pyx_v_start;

  /* "pysam/calignmentfile.pyx":2050
 *         self.setupIteratorData( tid, start, end, 1 )
 *         self.start = start
 *         self.end = end             # <<<<<<<<<<<<<<
 *         self.truncate = truncate
 * 
 */
  __pyx_v_self->end = __pyx_v_end;

  /* "pysam/calignmentfile.pyx":2051
 *         self.start = start
 *         self.end = end
 *         self.truncate = truncate             # <<<<<<<<<<<<<<
 * 
 *     def __next__(self):
 */
  __pyx_v_self->truncate = __pyx_v_truncate;

  /* "pysam/calignmentfile.pyx":2040
 *     '''iterates over a region only.
 *     '''
 *     def __cinit__(self, AlignmentFile samfile,             # <<<<<<<<<<<<<<
 *                   int tid = 0,
 *                   int start = 0,
 */

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

/* "pysam/calignmentfile.pyx":2053
 *         self.truncate = truncate
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_20IteratorColumnRegion_3__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_20IteratorColumnRegion_2__next__[] = "python version of next().\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_14calignmentfile_20IteratorColumnRegion_2__next__;
#endif
static PyObject *__pyx_pw_5pysam_14calignmentfile_20IteratorColumnRegion_3__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_20IteratorColumnRegion_2__next__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_20IteratorColumnRegion_2__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2053);

  /* "pysam/calignmentfile.pyx":2057
 *         """
 * 
 *         while 1:             # <<<<<<<<<<<<<<
 *             self.cnext()
 *             if self.n_plp < 0:
 */
  while (1) {

    /* "pysam/calignmentfile.pyx":2058
 * 
 *         while 1:
 *             self.cnext()             # <<<<<<<<<<<<<<
 *             if self.n_plp < 0:
 *                 raise ValueError("error during iteration" )
 */
    ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnRegion *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self));

    /* "pysam/calignmentfile.pyx":2059
 *         while 1:
 *             self.cnext()
 *             if self.n_plp < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration" )
 * 
 */
    __pyx_t_1 = ((__pyx_v_self->__pyx_base.n_plp < 0) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":2060
 *             self.cnext()
 *             if self.n_plp < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             if self.plp == NULL:
 */
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__67, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/calignmentfile.pyx":2062
 *                 raise ValueError("error during iteration" )
 * 
 *             if self.plp == NULL:             # <<<<<<<<<<<<<<
 *                 raise StopIteration
 * 
 */
    __pyx_t_1 = ((__pyx_v_self->__pyx_base.plp == NULL) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":2063
 * 
 *             if self.plp == NULL:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *             if self.truncate:
 */
      __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/calignmentfile.pyx":2065
 *                 raise StopIteration
 * 
 *             if self.truncate:             # <<<<<<<<<<<<<<
 *                 if self.start > self.pos: continue
 *                 if self.pos >= self.end: raise StopIteration
 */
    __pyx_t_1 = (__pyx_v_self->truncate != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":2066
 * 
 *             if self.truncate:
 *                 if self.start > self.pos: continue             # <<<<<<<<<<<<<<
 *                 if self.pos >= self.end: raise StopIteration
 * 
 */
      __pyx_t_1 = ((__pyx_v_self->start > __pyx_v_self->__pyx_base.pos) != 0);
      if (__pyx_t_1) {
        goto __pyx_L3_continue;
      }

      /* "pysam/calignmentfile.pyx":2067
 *             if self.truncate:
 *                 if self.start > self.pos: continue
 *                 if self.pos >= self.end: raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *             return makePileupColumn(&self.plp,
 */
      __pyx_t_1 = ((__pyx_v_self->__pyx_base.pos >= __pyx_v_self->end) != 0);
      if (__pyx_t_1) {
        __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2067; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "pysam/calignmentfile.pyx":2069
 *                 if self.pos >= self.end: raise StopIteration
 * 
 *             return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                    self.tid,
 *                                    self.pos,
 */
    __Pyx_XDECREF(__pyx_r);

    /* "pysam/calignmentfile.pyx":2072
 *                                    self.tid,
 *                                    self.pos,
 *                                    self.n_plp)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_2 = __pyx_f_5pysam_14calignmentfile_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); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
    __pyx_L3_continue:;
  }

  /* "pysam/calignmentfile.pyx":2053
 *         self.truncate = truncate
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.calignmentfile.IteratorColumnRegion.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2079
 *     """
 * 
 *     def __cinit__(self,             # <<<<<<<<<<<<<<
 *                   AlignmentFile samfile,
 *                   **kwargs):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_21IteratorColumnAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_21IteratorColumnAllRefs_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_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);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2079; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_14calignmentfile_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_filename = __pyx_f[0]; __pyx_lineno = 2079; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysam.calignmentfile.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_14calignmentfile_AlignmentFile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2080; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_21IteratorColumnAllRefs___cinit__(((struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_21IteratorColumnAllRefs___cinit__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__cinit__", 0);
  __Pyx_TraceCall("__cinit__", __pyx_f[0], 2079);

  /* "pysam/calignmentfile.pyx":2084
 * 
 *         # no iteration over empty files
 *         if not samfile.nreferences:             # <<<<<<<<<<<<<<
 *             raise StopIteration
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (__pyx_t_3) {

    /* "pysam/calignmentfile.pyx":2085
 *         # no iteration over empty files
 *         if not samfile.nreferences:
 *             raise StopIteration             # <<<<<<<<<<<<<<
 * 
 *         # initialize iterator
 */
    __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":2088
 * 
 *         # initialize iterator
 *         self.setupIteratorData(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_14calignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_14calignmentfile_max_pos, &__pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":2079
 *     """
 * 
 *     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.calignmentfile.IteratorColumnAllRefs.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2090
 *         self.setupIteratorData(self.tid, 0, max_pos, 1)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_21IteratorColumnAllRefs_3__next__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_21IteratorColumnAllRefs_2__next__[] = "python version of next().\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_14calignmentfile_21IteratorColumnAllRefs_2__next__;
#endif
static PyObject *__pyx_pw_5pysam_14calignmentfile_21IteratorColumnAllRefs_3__next__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__next__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_21IteratorColumnAllRefs_2__next__(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_21IteratorColumnAllRefs_2__next__(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__next__", 0);
  __Pyx_TraceCall("__next__", __pyx_f[0], 2090);

  /* "pysam/calignmentfile.pyx":2094
 *         """
 * 
 *         while 1:             # <<<<<<<<<<<<<<
 *             self.cnext()
 * 
 */
  while (1) {

    /* "pysam/calignmentfile.pyx":2095
 * 
 *         while 1:
 *             self.cnext()             # <<<<<<<<<<<<<<
 * 
 *             if self.n_plp < 0:
 */
    ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.cnext(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self));

    /* "pysam/calignmentfile.pyx":2097
 *             self.cnext()
 * 
 *             if self.n_plp < 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("error during iteration" )
 * 
 */
    __pyx_t_1 = ((__pyx_v_self->__pyx_base.n_plp < 0) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":2098
 * 
 *             if self.n_plp < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             # return result, if within same reference
 */
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__68, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }

    /* "pysam/calignmentfile.pyx":2101
 * 
 *             # return result, if within same reference
 *             if self.plp != NULL:             # <<<<<<<<<<<<<<
 *                 return makePileupColumn(&self.plp,
 *                                        self.tid,
 */
    __pyx_t_1 = ((__pyx_v_self->__pyx_base.plp != NULL) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":2102
 *             # return result, if within same reference
 *             if self.plp != NULL:
 *                 return makePileupColumn(&self.plp,             # <<<<<<<<<<<<<<
 *                                        self.tid,
 *                                        self.pos,
 */
      __Pyx_XDECREF(__pyx_r);

      /* "pysam/calignmentfile.pyx":2105
 *                                        self.tid,
 *                                        self.pos,
 *                                        self.n_plp)             # <<<<<<<<<<<<<<
 * 
 *             # otherwise, proceed to next reference or stop
 */
      __pyx_t_2 = __pyx_f_5pysam_14calignmentfile_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); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      goto __pyx_L0;
    }

    /* "pysam/calignmentfile.pyx":2108
 * 
 *             # otherwise, proceed to next reference or stop
 *             self.tid += 1             # <<<<<<<<<<<<<<
 *             if self.tid < self.samfile.nreferences:
 *                 self.setupIteratorData(self.tid, 0, max_pos, 0)
 */
    __pyx_v_self->__pyx_base.tid = (__pyx_v_self->__pyx_base.tid + 1);

    /* "pysam/calignmentfile.pyx":2109
 *             # otherwise, proceed to next reference or stop
 *             self.tid += 1
 *             if self.tid < self.samfile.nreferences:             # <<<<<<<<<<<<<<
 *                 self.setupIteratorData(self.tid, 0, max_pos, 0)
 *             else:
 */
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->__pyx_base.tid); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self->__pyx_base.samfile), __pyx_n_s_nreferences); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":2110
 *             self.tid += 1
 *             if self.tid < self.samfile.nreferences:
 *                 self.setupIteratorData(self.tid, 0, max_pos, 0)             # <<<<<<<<<<<<<<
 *             else:
 *                 raise StopIteration
 */
      __pyx_t_5.__pyx_n = 1;
      __pyx_t_5.multiple_iterators = 0;
      __pyx_t_4 = ((struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnAllRefs *)__pyx_v_self->__pyx_base.__pyx_vtab)->__pyx_base.setupIteratorData(((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)__pyx_v_self), __pyx_v_self->__pyx_base.tid, 0, __pyx_v_5pysam_14calignmentfile_max_pos, &__pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      goto __pyx_L7;
    }
    /*else*/ {

      /* "pysam/calignmentfile.pyx":2112
 *                 self.setupIteratorData(self.tid, 0, max_pos, 0)
 *             else:
 *                 raise StopIteration             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __Pyx_Raise(__pyx_builtin_StopIteration, 0, 0, 0);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L7:;
  }

  /* "pysam/calignmentfile.pyx":2090
 *         self.setupIteratorData(self.tid, 0, max_pos, 1)
 * 
 *     def __next__(self):             # <<<<<<<<<<<<<<
 *         """python version of next().
 *         """
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.calignmentfile.IteratorColumnAllRefs.__next__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2115
 * 
 * 
 * cdef inline int32_t _getQueryStart(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

static CYTHON_INLINE int32_t __pyx_f_5pysam_14calignmentfile__getQueryStart(bam1_t *__pyx_v_src) {
  uint32_t *__pyx_v_cigar_p;
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_op;
  uint32_t __pyx_v_start_offset;
  int32_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  uint16_t __pyx_t_2;
  int __pyx_t_3;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_getQueryStart", 0);
  __Pyx_TraceCall("_getQueryStart", __pyx_f[0], 2115);

  /* "pysam/calignmentfile.pyx":2118
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 *     cdef uint32_t start_offset = 0             # <<<<<<<<<<<<<<
 * 
 *     if pysam_get_n_cigar(src):
 */
  __pyx_v_start_offset = 0;

  /* "pysam/calignmentfile.pyx":2120
 *     cdef uint32_t start_offset = 0
 * 
 *     if pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_t_1 = (pysam_get_n_cigar(__pyx_v_src) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":2121
 * 
 *     if pysam_get_n_cigar(src):
 *         cigar_p = pysam_bam_get_cigar(src);             # <<<<<<<<<<<<<<
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
    __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

    /* "pysam/calignmentfile.pyx":2122
 *     if pysam_get_n_cigar(src):
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 */
    __pyx_t_2 = pysam_get_n_cigar(__pyx_v_src);
    for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_2; __pyx_v_k++) {

      /* "pysam/calignmentfile.pyx":2123
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             if op == BAM_CHARD_CLIP:
 *                 if start_offset != 0 and start_offset != src.core.l_qseq:
 */
      __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

      /* "pysam/calignmentfile.pyx":2124
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                 if start_offset != 0 and start_offset != src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 */
      __pyx_t_1 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0);
      if (__pyx_t_1) {

        /* "pysam/calignmentfile.pyx":2125
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 *                 if start_offset != 0 and start_offset != src.core.l_qseq:             # <<<<<<<<<<<<<<
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1
 */
        __pyx_t_3 = ((__pyx_v_start_offset != 0) != 0);
        if (__pyx_t_3) {
        } else {
          __pyx_t_1 = __pyx_t_3;
          goto __pyx_L8_bool_binop_done;
        }
        __pyx_t_3 = ((__pyx_v_start_offset != __pyx_v_src->core.l_qseq) != 0);
        __pyx_t_1 = __pyx_t_3;
        __pyx_L8_bool_binop_done:;
        if (__pyx_t_1) {

          /* "pysam/calignmentfile.pyx":2126
 *             if op == BAM_CHARD_CLIP:
 *                 if start_offset != 0 and start_offset != src.core.l_qseq:
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')             # <<<<<<<<<<<<<<
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:
 */
          PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_Invalid_clipping_in_CIGAR_string);

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

      /* "pysam/calignmentfile.pyx":2128
 *                     PyErr_SetString(ValueError, 'Invalid clipping in CIGAR string')
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 */
      __pyx_t_1 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
      if (__pyx_t_1) {

        /* "pysam/calignmentfile.pyx":2129
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *             else:
 *                 break
 */
        __pyx_v_start_offset = (__pyx_v_start_offset + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT));
        goto __pyx_L6;
      }
      /*else*/ {

        /* "pysam/calignmentfile.pyx":2131
 *                 start_offset += cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 *                 break             # <<<<<<<<<<<<<<
 * 
 *     return start_offset
 */
        goto __pyx_L5_break;
      }
      __pyx_L6:;
    }
    __pyx_L5_break:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":2133
 *                 break
 * 
 *     return start_offset             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_start_offset;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2115
 * 
 * 
 * cdef inline int32_t _getQueryStart(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

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

/* "pysam/calignmentfile.pyx":2136
 * 
 * 
 * cdef inline int32_t _getQueryEnd(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

static CYTHON_INLINE int32_t __pyx_f_5pysam_14calignmentfile__getQueryEnd(bam1_t *__pyx_v_src) {
  uint32_t *__pyx_v_cigar_p;
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_op;
  uint32_t __pyx_v_end_offset;
  int32_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_getQueryEnd", 0);
  __Pyx_TraceCall("_getQueryEnd", __pyx_f[0], 2136);

  /* "pysam/calignmentfile.pyx":2139
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 *     cdef uint32_t end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *     if pysam_get_n_cigar(src) > 1:
 */
  __pyx_t_1 = __pyx_v_src->core.l_qseq;
  __pyx_v_end_offset = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2141
 *     cdef uint32_t end_offset = src.core.l_qseq
 * 
 *     if pysam_get_n_cigar(src) > 1:             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) > 1) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2142
 * 
 *     if pysam_get_n_cigar(src) > 1:
 *         cigar_p = pysam_bam_get_cigar(src);             # <<<<<<<<<<<<<<
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
    __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

    /* "pysam/calignmentfile.pyx":2143
 *     if pysam_get_n_cigar(src) > 1:
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from pysam_get_n_cigar(src) > k >= 1:             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 */
    for (__pyx_v_k = pysam_get_n_cigar(__pyx_v_src)-1 + 1; __pyx_v_k >= 1 + 1; ) { __pyx_v_k--;

      /* "pysam/calignmentfile.pyx":2144
 *         cigar_p = pysam_bam_get_cigar(src);
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             if op == BAM_CHARD_CLIP:
 *                 if end_offset != 0 and end_offset != src.core.l_qseq:
 */
      __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

      /* "pysam/calignmentfile.pyx":2145
 *         for k from pysam_get_n_cigar(src) > k >= 1:
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                 if end_offset != 0 and end_offset != src.core.l_qseq:
 *                     PyErr_SetString(ValueError,
 */
      __pyx_t_2 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0);
      if (__pyx_t_2) {

        /* "pysam/calignmentfile.pyx":2146
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             if op == BAM_CHARD_CLIP:
 *                 if end_offset != 0 and end_offset != src.core.l_qseq:             # <<<<<<<<<<<<<<
 *                     PyErr_SetString(ValueError,
 *                                     'Invalid clipping in CIGAR string')
 */
        __pyx_t_3 = ((__pyx_v_end_offset != 0) != 0);
        if (__pyx_t_3) {
        } else {
          __pyx_t_2 = __pyx_t_3;
          goto __pyx_L8_bool_binop_done;
        }
        __pyx_t_3 = ((__pyx_v_end_offset != __pyx_v_src->core.l_qseq) != 0);
        __pyx_t_2 = __pyx_t_3;
        __pyx_L8_bool_binop_done:;
        if (__pyx_t_2) {

          /* "pysam/calignmentfile.pyx":2147
 *             if op == BAM_CHARD_CLIP:
 *                 if end_offset != 0 and end_offset != src.core.l_qseq:
 *                     PyErr_SetString(ValueError,             # <<<<<<<<<<<<<<
 *                                     'Invalid clipping in CIGAR string')
 *                     return -1
 */
          PyErr_SetString(__pyx_builtin_ValueError, __pyx_k_Invalid_clipping_in_CIGAR_string);

          /* "pysam/calignmentfile.pyx":2149
 *                     PyErr_SetString(ValueError,
 *                                     'Invalid clipping in CIGAR string')
 *                     return -1             # <<<<<<<<<<<<<<
 *             elif op == BAM_CSOFT_CLIP:
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 */
          __pyx_r = -1;
          goto __pyx_L0;
        }
        goto __pyx_L6;
      }

      /* "pysam/calignmentfile.pyx":2150
 *                                     'Invalid clipping in CIGAR string')
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 */
      __pyx_t_2 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
      if (__pyx_t_2) {

        /* "pysam/calignmentfile.pyx":2151
 *                     return -1
 *             elif op == BAM_CSOFT_CLIP:
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *             else:
 *                 break
 */
        __pyx_v_end_offset = (__pyx_v_end_offset - ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT));
        goto __pyx_L6;
      }
      /*else*/ {

        /* "pysam/calignmentfile.pyx":2153
 *                 end_offset -= cigar_p[k] >> BAM_CIGAR_SHIFT
 *             else:
 *                 break             # <<<<<<<<<<<<<<
 * 
 *     if end_offset == 0:
 */
        goto __pyx_L5_break;
      }
      __pyx_L6:;
    }
    __pyx_L5_break:;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":2155
 *                 break
 * 
 *     if end_offset == 0:             # <<<<<<<<<<<<<<
 *         end_offset = src.core.l_qseq
 * 
 */
  __pyx_t_2 = ((__pyx_v_end_offset == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2156
 * 
 *     if end_offset == 0:
 *         end_offset = src.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *     return end_offset
 */
    __pyx_t_1 = __pyx_v_src->core.l_qseq;
    __pyx_v_end_offset = __pyx_t_1;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "pysam/calignmentfile.pyx":2158
 *         end_offset = src.core.l_qseq
 * 
 *     return end_offset             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_end_offset;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2136
 * 
 * 
 * cdef inline int32_t _getQueryEnd(bam1_t *src) except -1:             # <<<<<<<<<<<<<<
 *     cdef uint32_t * cigar_p
 *     cdef uint32_t k, op
 */

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

/* "pysam/calignmentfile.pyx":2161
 * 
 * 
 * cdef inline object _getSequenceRange(bam1_t *src,             # <<<<<<<<<<<<<<
 *                                      uint32_t start, uint32_t end):
 *     cdef uint8_t * p
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_14calignmentfile__getSequenceRange(bam1_t *__pyx_v_src, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
  uint8_t *__pyx_v_p;
  uint32_t __pyx_v_k;
  char *__pyx_v_s;
  PyObject *__pyx_v_seq = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  char *__pyx_t_3;
  uint32_t __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_getSequenceRange", 0);
  __Pyx_TraceCall("_getSequenceRange", __pyx_f[0], 2161);

  /* "pysam/calignmentfile.pyx":2167
 *     cdef char * s
 * 
 *     if not src.core.l_qseq:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = ((!(__pyx_v_src->core.l_qseq != 0)) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":2168
 * 
 *     if not src.core.l_qseq:
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2170
 *         return None
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)             # <<<<<<<<<<<<<<
 *     s   = <char*>seq
 *     p   = pysam_bam_get_seq(src)
 */
  __pyx_t_2 = PyBytes_FromStringAndSize(NULL, (__pyx_v_end - __pyx_v_start)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_seq = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":2171
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)
 *     s   = <char*>seq             # <<<<<<<<<<<<<<
 *     p   = pysam_bam_get_seq(src)
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_s = ((char *)__pyx_t_3);

  /* "pysam/calignmentfile.pyx":2172
 *     seq = PyBytes_FromStringAndSize(NULL, end - start)
 *     s   = <char*>seq
 *     p   = pysam_bam_get_seq(src)             # <<<<<<<<<<<<<<
 * 
 *     for k from start <= k < end:
 */
  __pyx_v_p = pysam_bam_get_seq(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":2174
 *     p   = pysam_bam_get_seq(src)
 * 
 *     for k from start <= k < end:             # <<<<<<<<<<<<<<
 *         # equivalent to seq_nt16_str[bam1_seqi(s, i)] (see bam.c)
 *         # note: do not use string literal as it will be a python string
 */
  __pyx_t_4 = __pyx_v_end;
  for (__pyx_v_k = __pyx_v_start; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {

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

  /* "pysam/calignmentfile.pyx":2179
 *         s[k-start] = seq_nt16_str[p[k/2] >> 4 * (1 - k%2) & 0xf]
 * 
 *     return _charptr_to_str(seq)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyObject_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __pyx_f_5pysam_14calignmentfile__charptr_to_str(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2161
 * 
 * 
 * cdef inline object _getSequenceRange(bam1_t *src,             # <<<<<<<<<<<<<<
 *                                      uint32_t start, uint32_t end):
 *     cdef uint8_t * p
 */

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

/* "pysam/calignmentfile.pyx":2182
 * 
 * 
 * cdef inline object _getQualitiesRange(bam1_t *src,             # <<<<<<<<<<<<<<
 *                                       uint32_t start,
 *                                       uint32_t end):
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_14calignmentfile__getQualitiesRange(bam1_t *__pyx_v_src, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
  uint8_t *__pyx_v_p;
  arrayobject *__pyx_v_result = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  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_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_getQualitiesRange", 0);
  __Pyx_TraceCall("_getQualitiesRange", __pyx_f[0], 2182);

  /* "pysam/calignmentfile.pyx":2190
 *     cdef uint32_t k
 * 
 *     p = pysam_bam_get_qual(src)             # <<<<<<<<<<<<<<
 *     if p[0] == 0xff:
 *         return None
 */
  __pyx_v_p = pysam_bam_get_qual(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":2191
 * 
 *     p = pysam_bam_get_qual(src)
 *     if p[0] == 0xff:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = (((__pyx_v_p[0]) == 0xff) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":2192
 *     p = pysam_bam_get_qual(src)
 *     if p[0] == 0xff:
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     # 'B': unsigned char
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2195
 * 
 *     # 'B': unsigned char
 *     cdef array.array result = array.array('B', [0])             # <<<<<<<<<<<<<<
 *     array.resize(result, end - start)
 * 
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_int_0);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_n_s_B);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_B);
  __Pyx_GIVEREF(__pyx_n_s_B);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7cpython_5array_array)), __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_result = ((arrayobject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":2196
 *     # 'B': unsigned char
 *     cdef array.array result = array.array('B', [0])
 *     array.resize(result, end - start)             # <<<<<<<<<<<<<<
 * 
 *     # copy data
 */
  __pyx_t_4 = resize(__pyx_v_result, (__pyx_v_end - __pyx_v_start)); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":2199
 * 
 *     # copy data
 *     memcpy(result.data.as_voidptr, <void*>&p[start], end - start)             # <<<<<<<<<<<<<<
 * 
 *     return result
 */
  memcpy(__pyx_v_result->data.as_voidptr, ((void *)(&(__pyx_v_p[__pyx_v_start]))), (__pyx_v_end - __pyx_v_start));

  /* "pysam/calignmentfile.pyx":2201
 *     memcpy(result.data.as_voidptr, <void*>&p[start], end - start)
 * 
 *     return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_result));
  __pyx_r = ((PyObject *)__pyx_v_result);
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2182
 * 
 * 
 * cdef inline object _getQualitiesRange(bam1_t *src,             # <<<<<<<<<<<<<<
 *                                       uint32_t start,
 *                                       uint32_t end):
 */

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

/* "pysam/calignmentfile.pyx":2204
 * 
 * 
 * def toQualityString(qualities):             # <<<<<<<<<<<<<<
 *     '''convert a list of quality score to the string
 *     representation used in the SAM format.'''
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_1toQualityString(PyObject *__pyx_self, PyObject *__pyx_v_qualities); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_toQualityString[] = "toQualityString(qualities)\nconvert a list of quality score to the string\n    representation used in the SAM format.";
static PyMethodDef __pyx_mdef_5pysam_14calignmentfile_1toQualityString = {"toQualityString", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_1toQualityString, METH_O, __pyx_doc_5pysam_14calignmentfile_toQualityString};
static PyObject *__pyx_pw_5pysam_14calignmentfile_1toQualityString(PyObject *__pyx_self, PyObject *__pyx_v_qualities) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("toQualityString (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_toQualityString(__pyx_self, ((PyObject *)__pyx_v_qualities));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_toQualityString(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_qualities) {
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(__pyx_codeobj__69)
  __Pyx_RefNannySetupContext("toQualityString", 0);
  __Pyx_TraceCall("toQualityString", __pyx_f[0], 2204);

  /* "pysam/calignmentfile.pyx":2207
 *     '''convert a list of quality score to the string
 *     representation used in the SAM format.'''
 *     if qualities is None:             # <<<<<<<<<<<<<<
 *         return None
 *     return "".join([chr(x+33) for x in qualities])
 */
  __pyx_t_1 = (__pyx_v_qualities == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2208
 *     representation used in the SAM format.'''
 *     if qualities is None:
 *         return None             # <<<<<<<<<<<<<<
 *     return "".join([chr(x+33) for x in qualities])
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2209
 *     if qualities is None:
 *         return None
 *     return "".join([chr(x+33) for x in qualities])             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (likely(PyList_CheckExact(__pyx_v_qualities)) || PyTuple_CheckExact(__pyx_v_qualities)) {
    __pyx_t_4 = __pyx_v_qualities; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_qualities); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_Add(__pyx_v_x, __pyx_int_33); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyString_Join(__pyx_kp_s__7, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2204
 * 
 * 
 * def toQualityString(qualities):             # <<<<<<<<<<<<<<
 *     '''convert a list of quality score to the string
 *     representation used in the SAM format.'''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.calignmentfile.toQualityString", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2212
 * 
 * 
 * def fromQualityString(quality_string):             # <<<<<<<<<<<<<<
 *     '''return a list of quality scores from the
 *     stringn representation of quality scores used
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_3fromQualityString(PyObject *__pyx_self, PyObject *__pyx_v_quality_string); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_2fromQualityString[] = "fromQualityString(quality_string)\nreturn a list of quality scores from the\n    stringn representation of quality scores used\n    in the SAM format.";
static PyMethodDef __pyx_mdef_5pysam_14calignmentfile_3fromQualityString = {"fromQualityString", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_3fromQualityString, METH_O, __pyx_doc_5pysam_14calignmentfile_2fromQualityString};
static PyObject *__pyx_pw_5pysam_14calignmentfile_3fromQualityString(PyObject *__pyx_self, PyObject *__pyx_v_quality_string) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("fromQualityString (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_2fromQualityString(__pyx_self, ((PyObject *)__pyx_v_quality_string));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_2fromQualityString(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_quality_string) {
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(__pyx_codeobj__70)
  __Pyx_RefNannySetupContext("fromQualityString", 0);
  __Pyx_TraceCall("fromQualityString", __pyx_f[0], 2212);

  /* "pysam/calignmentfile.pyx":2216
 *     stringn representation of quality scores used
 *     in the SAM format.'''
 *     if quality_string is None:             # <<<<<<<<<<<<<<
 *         return None
 *     return array.array('B', [ord(x)-33 for x in quality_string])
 */
  __pyx_t_1 = (__pyx_v_quality_string == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2217
 *     in the SAM format.'''
 *     if quality_string is None:
 *         return None             # <<<<<<<<<<<<<<
 *     return array.array('B', [ord(x)-33 for x in quality_string])
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2218
 *     if quality_string is None:
 *         return None
 *     return array.array('B', [ord(x)-33 for x in quality_string])             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (likely(PyList_CheckExact(__pyx_v_quality_string)) || PyTuple_CheckExact(__pyx_v_quality_string)) {
    __pyx_t_4 = __pyx_v_quality_string; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_quality_string); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_v_x);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_x);
    __Pyx_GIVEREF(__pyx_v_x);
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ord, __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_Subtract(__pyx_t_8, __pyx_int_33); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_n_s_B);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_B);
  __Pyx_GIVEREF(__pyx_n_s_B);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7cpython_5array_array)), __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2218; __pyx_clineno = __LINE__; goto __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/calignmentfile.pyx":2212
 * 
 * 
 * def fromQualityString(quality_string):             # <<<<<<<<<<<<<<
 *     '''return a list of quality scores from the
 *     stringn representation of quality scores used
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.calignmentfile.fromQualityString", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2221
 * 
 * 
 * cdef inline uint8_t _get_value_code(value, value_type=None):             # <<<<<<<<<<<<<<
 *     '''guess type code for a *value*. If *value_type* is None,
 *     the type code will be inferred based on the Python type of
 */

static CYTHON_INLINE uint8_t __pyx_f_5pysam_14calignmentfile__get_value_code(PyObject *__pyx_v_value, struct __pyx_opt_args_5pysam_14calignmentfile__get_value_code *__pyx_optional_args) {
  PyObject *__pyx_v_value_type = ((PyObject *)Py_None);
  uint8_t __pyx_v_type_code;
  char *__pyx_v__char_type;
  uint8_t __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  char *__pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_get_value_code", 0);
  __Pyx_TraceCall("_get_value_code", __pyx_f[0], 2221);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_value_type = __pyx_optional_args->value_type;
    }
  }
  __Pyx_INCREF(__pyx_v_value_type);

  /* "pysam/calignmentfile.pyx":2228
 *     cdef char * _char_type
 * 
 *     if value_type is None:             # <<<<<<<<<<<<<<
 *         if isinstance(value, int):
 *             type_code = 'i'
 */
  __pyx_t_1 = (__pyx_v_value_type == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2229
 * 
 *     if value_type is None:
 *         if isinstance(value, int):             # <<<<<<<<<<<<<<
 *             type_code = 'i'
 *         elif isinstance(value, float):
 */
    __pyx_t_2 = PyInt_Check(__pyx_v_value); 
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":2230
 *     if value_type is None:
 *         if isinstance(value, int):
 *             type_code = 'i'             # <<<<<<<<<<<<<<
 *         elif isinstance(value, float):
 *             type_code = 'd'
 */
      __pyx_v_type_code = 'i';
      goto __pyx_L4;
    }

    /* "pysam/calignmentfile.pyx":2231
 *         if isinstance(value, int):
 *             type_code = 'i'
 *         elif isinstance(value, float):             # <<<<<<<<<<<<<<
 *             type_code = 'd'
 *         elif isinstance(value, str):
 */
    __pyx_t_1 = PyFloat_Check(__pyx_v_value); 
    __pyx_t_2 = (__pyx_t_1 != 0);
    if (__pyx_t_2) {

      /* "pysam/calignmentfile.pyx":2232
 *             type_code = 'i'
 *         elif isinstance(value, float):
 *             type_code = 'd'             # <<<<<<<<<<<<<<
 *         elif isinstance(value, str):
 *             type_code = 'Z'
 */
      __pyx_v_type_code = 'd';
      goto __pyx_L4;
    }

    /* "pysam/calignmentfile.pyx":2233
 *         elif isinstance(value, float):
 *             type_code = 'd'
 *         elif isinstance(value, str):             # <<<<<<<<<<<<<<
 *             type_code = 'Z'
 *         elif isinstance(value, bytes):
 */
    __pyx_t_2 = PyString_Check(__pyx_v_value); 
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":2234
 *             type_code = 'd'
 *         elif isinstance(value, str):
 *             type_code = 'Z'             # <<<<<<<<<<<<<<
 *         elif isinstance(value, bytes):
 *             type_code = 'Z'
 */
      __pyx_v_type_code = 'Z';
      goto __pyx_L4;
    }

    /* "pysam/calignmentfile.pyx":2235
 *         elif isinstance(value, str):
 *             type_code = 'Z'
 *         elif isinstance(value, bytes):             # <<<<<<<<<<<<<<
 *             type_code = 'Z'
 *         else:
 */
    __pyx_t_1 = PyBytes_Check(__pyx_v_value); 
    __pyx_t_2 = (__pyx_t_1 != 0);
    if (__pyx_t_2) {

      /* "pysam/calignmentfile.pyx":2236
 *             type_code = 'Z'
 *         elif isinstance(value, bytes):
 *             type_code = 'Z'             # <<<<<<<<<<<<<<
 *         else:
 *             return 0
 */
      __pyx_v_type_code = 'Z';
      goto __pyx_L4;
    }
    /*else*/ {

      /* "pysam/calignmentfile.pyx":2238
 *             type_code = 'Z'
 *         else:
 *             return 0             # <<<<<<<<<<<<<<
 *     else:
 *         if value_type not in 'Zidf':
 */
      __pyx_r = 0;
      goto __pyx_L0;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":2240
 *             return 0
 *     else:
 *         if value_type not in 'Zidf':             # <<<<<<<<<<<<<<
 *             return 0
 *         value_type = _forceBytes(value_type)
 */
    __pyx_t_2 = (__Pyx_PySequence_Contains(__pyx_v_value_type, __pyx_n_s_Zidf, Py_NE)); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":2241
 *     else:
 *         if value_type not in 'Zidf':
 *             return 0             # <<<<<<<<<<<<<<
 *         value_type = _forceBytes(value_type)
 *         _char_type = value_type
 */
      __pyx_r = 0;
      goto __pyx_L0;
    }

    /* "pysam/calignmentfile.pyx":2242
 *         if value_type not in 'Zidf':
 *             return 0
 *         value_type = _forceBytes(value_type)             # <<<<<<<<<<<<<<
 *         _char_type = value_type
 *         type_code = (<uint8_t*>_char_type)[0]
 */
    __pyx_t_3 = __pyx_f_5pysam_14calignmentfile__forceBytes(__pyx_v_value_type); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2242; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_value_type, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/calignmentfile.pyx":2243
 *             return 0
 *         value_type = _forceBytes(value_type)
 *         _char_type = value_type             # <<<<<<<<<<<<<<
 *         type_code = (<uint8_t*>_char_type)[0]
 * 
 */
    __pyx_t_4 = __Pyx_PyObject_AsString(__pyx_v_value_type); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v__char_type = __pyx_t_4;

    /* "pysam/calignmentfile.pyx":2244
 *         value_type = _forceBytes(value_type)
 *         _char_type = value_type
 *         type_code = (<uint8_t*>_char_type)[0]             # <<<<<<<<<<<<<<
 * 
 *     return type_code
 */
    __pyx_v_type_code = (((uint8_t *)__pyx_v__char_type)[0]);
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":2246
 *         type_code = (<uint8_t*>_char_type)[0]
 * 
 *     return type_code             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_type_code;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2221
 * 
 * 
 * cdef inline uint8_t _get_value_code(value, value_type=None):             # <<<<<<<<<<<<<<
 *     '''guess type code for a *value*. If *value_type* is None,
 *     the type code will be inferred based on the Python type of
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_WriteUnraisable("pysam.calignmentfile._get_value_code", __pyx_clineno, __pyx_lineno, __pyx_filename, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_value_type);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2249
 * 
 * 
 * cdef inline _get_value_type(value, maximum_value=None):             # <<<<<<<<<<<<<<
 *     '''returns the value type of a value.
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_14calignmentfile__get_value_type(PyObject *__pyx_v_value, struct __pyx_opt_args_5pysam_14calignmentfile__get_value_type *__pyx_optional_args) {
  PyObject *__pyx_v_maximum_value = ((PyObject *)Py_None);
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_v_valuetype = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_get_value_type", 0);
  __Pyx_TraceCall("_get_value_type", __pyx_f[0], 2249);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_maximum_value = __pyx_optional_args->maximum_value;
    }
  }
  __Pyx_INCREF(__pyx_v_value);
  __Pyx_INCREF(__pyx_v_maximum_value);

  /* "pysam/calignmentfile.pyx":2256
 *     '''
 * 
 *     if maximum_value is None:             # <<<<<<<<<<<<<<
 *         maximum_value = value
 * 
 */
  __pyx_t_1 = (__pyx_v_maximum_value == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2257
 * 
 *     if maximum_value is None:
 *         maximum_value = value             # <<<<<<<<<<<<<<
 * 
 *     t = type(value)
 */
    __Pyx_INCREF(__pyx_v_value);
    __Pyx_DECREF_SET(__pyx_v_maximum_value, __pyx_v_value);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":2259
 *         maximum_value = value
 * 
 *     t = type(value)             # <<<<<<<<<<<<<<
 * 
 *     if t is float:
 */
  __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
  __pyx_v_t = ((PyObject*)((PyObject *)Py_TYPE(__pyx_v_value)));

  /* "pysam/calignmentfile.pyx":2261
 *     t = type(value)
 * 
 *     if t is float:             # <<<<<<<<<<<<<<
 *         valuetype = b'f'
 *     elif t is int:
 */
  __pyx_t_2 = (__pyx_v_t == ((PyObject*)(&PyFloat_Type)));
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":2262
 * 
 *     if t is float:
 *         valuetype = b'f'             # <<<<<<<<<<<<<<
 *     elif t is int:
 *         # signed ints
 */
    __Pyx_INCREF(__pyx_n_b_f);
    __pyx_v_valuetype = __pyx_n_b_f;
    goto __pyx_L4;
  }

  /* "pysam/calignmentfile.pyx":2263
 *     if t is float:
 *         valuetype = b'f'
 *     elif t is int:             # <<<<<<<<<<<<<<
 *         # signed ints
 *         if value < 0:
 */
  __pyx_t_1 = (__pyx_v_t == ((PyObject*)(&PyInt_Type)));
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2265
 *     elif t is int:
 *         # signed ints
 *         if value < 0:             # <<<<<<<<<<<<<<
 *             if value >= -128 and maximum_value < 128:
 *                 valuetype = b'c'
 */
    __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2265; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_2) {

      /* "pysam/calignmentfile.pyx":2266
 *         # signed ints
 *         if value < 0:
 *             if value >= -128 and maximum_value < 128:             # <<<<<<<<<<<<<<
 *                 valuetype = b'c'
 *             elif value >= -32768 and maximum_value < 32768:
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_128, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_1) {
      } else {
        __pyx_t_2 = __pyx_t_1;
        goto __pyx_L7_bool_binop_done;
      }
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_128, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2266; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_2 = __pyx_t_1;
      __pyx_L7_bool_binop_done:;
      if (__pyx_t_2) {

        /* "pysam/calignmentfile.pyx":2267
 *         if value < 0:
 *             if value >= -128 and maximum_value < 128:
 *                 valuetype = b'c'             # <<<<<<<<<<<<<<
 *             elif value >= -32768 and maximum_value < 32768:
 *                 valuetype = b's'
 */
        __Pyx_INCREF(__pyx_n_b_c);
        __pyx_v_valuetype = __pyx_n_b_c;
        goto __pyx_L6;
      }

      /* "pysam/calignmentfile.pyx":2268
 *             if value >= -128 and maximum_value < 128:
 *                 valuetype = b'c'
 *             elif value >= -32768 and maximum_value < 32768:             # <<<<<<<<<<<<<<
 *                 valuetype = b's'
 *             elif value < -2147483648 or maximum_value >= 2147483648:
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_32768, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_1) {
      } else {
        __pyx_t_2 = __pyx_t_1;
        goto __pyx_L9_bool_binop_done;
      }
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_32768, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2268; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_2 = __pyx_t_1;
      __pyx_L9_bool_binop_done:;
      if (__pyx_t_2) {

        /* "pysam/calignmentfile.pyx":2269
 *                 valuetype = b'c'
 *             elif value >= -32768 and maximum_value < 32768:
 *                 valuetype = b's'             # <<<<<<<<<<<<<<
 *             elif value < -2147483648 or maximum_value >= 2147483648:
 *                 raise ValueError(
 */
        __Pyx_INCREF(__pyx_n_b_s_2);
        __pyx_v_valuetype = __pyx_n_b_s_2;
        goto __pyx_L6;
      }

      /* "pysam/calignmentfile.pyx":2270
 *             elif value >= -32768 and maximum_value < 32768:
 *                 valuetype = b's'
 *             elif value < -2147483648 or maximum_value >= 2147483648:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "at least one signed integer out of range of "
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_value, __pyx_int_neg_2147483648, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!__pyx_t_1) {
      } else {
        __pyx_t_2 = __pyx_t_1;
        goto __pyx_L11_bool_binop_done;
      }
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_2147483648, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2270; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_2 = __pyx_t_1;
      __pyx_L11_bool_binop_done:;
      if (__pyx_t_2) {

        /* "pysam/calignmentfile.pyx":2271
 *                 valuetype = b's'
 *             elif value < -2147483648 or maximum_value >= 2147483648:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "at least one signed integer out of range of "
 *                     "BAM/SAM specification")
 */
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__71, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      /*else*/ {

        /* "pysam/calignmentfile.pyx":2275
 *                     "BAM/SAM specification")
 *             else:
 *                 valuetype = b'i'             # <<<<<<<<<<<<<<
 *         # unsigned ints
 *         else:
 */
        __Pyx_INCREF(__pyx_n_b_i);
        __pyx_v_valuetype = __pyx_n_b_i;
      }
      __pyx_L6:;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "pysam/calignmentfile.pyx":2278
 *         # unsigned ints
 *         else:
 *             if maximum_value < 256:             # <<<<<<<<<<<<<<
 *                 valuetype = b'C'
 *             elif maximum_value < 65536:
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_256, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_2) {

        /* "pysam/calignmentfile.pyx":2279
 *         else:
 *             if maximum_value < 256:
 *                 valuetype = b'C'             # <<<<<<<<<<<<<<
 *             elif maximum_value < 65536:
 *                 valuetype = b'S'
 */
        __Pyx_INCREF(__pyx_n_b_C);
        __pyx_v_valuetype = __pyx_n_b_C;
        goto __pyx_L13;
      }

      /* "pysam/calignmentfile.pyx":2280
 *             if maximum_value < 256:
 *                 valuetype = b'C'
 *             elif maximum_value < 65536:             # <<<<<<<<<<<<<<
 *                 valuetype = b'S'
 *             elif maximum_value >= 4294967296:
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_65536, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_2) {

        /* "pysam/calignmentfile.pyx":2281
 *                 valuetype = b'C'
 *             elif maximum_value < 65536:
 *                 valuetype = b'S'             # <<<<<<<<<<<<<<
 *             elif maximum_value >= 4294967296:
 *                 raise ValueError(
 */
        __Pyx_INCREF(__pyx_n_b_S);
        __pyx_v_valuetype = __pyx_n_b_S;
        goto __pyx_L13;
      }

      /* "pysam/calignmentfile.pyx":2282
 *             elif maximum_value < 65536:
 *                 valuetype = b'S'
 *             elif maximum_value >= 4294967296:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "at least one integer out of range of BAM/SAM specification")
 */
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_maximum_value, __pyx_int_4294967296, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_2) {

        /* "pysam/calignmentfile.pyx":2283
 *                 valuetype = b'S'
 *             elif maximum_value >= 4294967296:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "at least one integer out of range of BAM/SAM specification")
 *             else:
 */
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__72, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      /*else*/ {

        /* "pysam/calignmentfile.pyx":2286
 *                     "at least one integer out of range of BAM/SAM specification")
 *             else:
 *                 valuetype = b'I'             # <<<<<<<<<<<<<<
 *     else:
 *         # Note: hex strings (H) are not supported yet
 */
        __Pyx_INCREF(__pyx_n_b_I);
        __pyx_v_valuetype = __pyx_n_b_I;
      }
      __pyx_L13:;
    }
    __pyx_L5:;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":2289
 *     else:
 *         # Note: hex strings (H) are not supported yet
 *         if t is not bytes:             # <<<<<<<<<<<<<<
 *             value = value.encode('ascii')
 *         if len(value) == 1:
 */
    __pyx_t_2 = (__pyx_v_t != ((PyObject*)(&PyBytes_Type)));
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":2290
 *         # Note: hex strings (H) are not supported yet
 *         if t is not bytes:
 *             value = value.encode('ascii')             # <<<<<<<<<<<<<<
 *         if len(value) == 1:
 *             valuetype = b"A"
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_encode); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__73, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_4);
      __pyx_t_4 = 0;
      goto __pyx_L14;
    }
    __pyx_L14:;

    /* "pysam/calignmentfile.pyx":2291
 *         if t is not bytes:
 *             value = value.encode('ascii')
 *         if len(value) == 1:             # <<<<<<<<<<<<<<
 *             valuetype = b"A"
 *         else:
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2291; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = ((__pyx_t_5 == 1) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":2292
 *             value = value.encode('ascii')
 *         if len(value) == 1:
 *             valuetype = b"A"             # <<<<<<<<<<<<<<
 *         else:
 *             valuetype = b'Z'
 */
      __Pyx_INCREF(__pyx_n_b_A);
      __pyx_v_valuetype = __pyx_n_b_A;
      goto __pyx_L15;
    }
    /*else*/ {

      /* "pysam/calignmentfile.pyx":2294
 *             valuetype = b"A"
 *         else:
 *             valuetype = b'Z'             # <<<<<<<<<<<<<<
 * 
 *     return valuetype
 */
      __Pyx_INCREF(__pyx_n_b_Z);
      __pyx_v_valuetype = __pyx_n_b_Z;
    }
    __pyx_L15:;
  }
  __pyx_L4:;

  /* "pysam/calignmentfile.pyx":2296
 *             valuetype = b'Z'
 * 
 *     return valuetype             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_valuetype);
  __pyx_r = __pyx_v_valuetype;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2249
 * 
 * 
 * cdef inline _get_value_type(value, maximum_value=None):             # <<<<<<<<<<<<<<
 *     '''returns the value type of a value.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.calignmentfile._get_value_type", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_valuetype);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_maximum_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2299
 * 
 * 
 * cdef inline _pack_tags(tags):             # <<<<<<<<<<<<<<
 *     """pack a list of tags. Each tag is a tuple of (tag, tuple).
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5pysam_14calignmentfile__pack_tags(PyObject *__pyx_v_tags) {
  PyObject *__pyx_v_fmts = NULL;
  PyObject *__pyx_v_args = NULL;
  PyObject *__pyx_v_tag = NULL;
  PyObject *__pyx_v_pytag = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_v_valuetype = NULL;
  PyObject *__pyx_v_datatype2format = NULL;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_v_datafmt = NULL;
  PyObject *__pyx_v_fmt = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *(*__pyx_t_4)(PyObject *);
  Py_ssize_t __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;
  int __pyx_t_11;
  int __pyx_t_12;
  struct __pyx_opt_args_5pysam_14calignmentfile__get_value_type __pyx_t_13;
  int __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("_pack_tags", 0);
  __Pyx_TraceCall("_pack_tags", __pyx_f[0], 2299);

  /* "pysam/calignmentfile.pyx":2308
 *     to used in a call to struct.pack_into.
 *     """
 *     fmts, args = ["<"], []             # <<<<<<<<<<<<<<
 * 
 *     for tag in tags:
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_kp_s__74);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_kp_s__74);
  __Pyx_GIVEREF(__pyx_kp_s__74);
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2308; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_fmts = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_v_args = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":2310
 *     fmts, args = ["<"], []
 * 
 *     for tag in tags:             # <<<<<<<<<<<<<<
 * 
 *         if len(tag) == 2:
 */
  if (likely(PyList_CheckExact(__pyx_v_tags)) || PyTuple_CheckExact(__pyx_v_tags)) {
    __pyx_t_2 = __pyx_v_tags; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_tags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  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_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_4(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2310; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_tag, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/calignmentfile.pyx":2312
 *     for tag in tags:
 * 
 *         if len(tag) == 2:             # <<<<<<<<<<<<<<
 *             pytag, value = tag
 *             valuetype = None
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2312; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = ((__pyx_t_5 == 2) != 0);
    if (__pyx_t_6) {

      /* "pysam/calignmentfile.pyx":2313
 * 
 *         if len(tag) == 2:
 *             pytag, value = tag             # <<<<<<<<<<<<<<
 *             valuetype = None
 *         elif len(tag) == 3:
 */
      if ((likely(PyTuple_CheckExact(__pyx_v_tag))) || (PyList_CheckExact(__pyx_v_tag))) {
        PyObject* sequence = __pyx_v_tag;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_7);
        #else
        __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      } else {
        Py_ssize_t index = -1;
        __pyx_t_8 = PyObject_GetIter(__pyx_v_tag); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
        index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_1);
        index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L7_unpacking_done;
        __pyx_L6_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L7_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_pytag, __pyx_t_1);
      __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_7);
      __pyx_t_7 = 0;

      /* "pysam/calignmentfile.pyx":2314
 *         if len(tag) == 2:
 *             pytag, value = tag
 *             valuetype = None             # <<<<<<<<<<<<<<
 *         elif len(tag) == 3:
 *             pytag, value, valuetype = tag
 */
      __Pyx_INCREF(Py_None);
      __Pyx_XDECREF_SET(__pyx_v_valuetype, Py_None);
      goto __pyx_L5;
    }

    /* "pysam/calignmentfile.pyx":2315
 *             pytag, value = tag
 *             valuetype = None
 *         elif len(tag) == 3:             # <<<<<<<<<<<<<<
 *             pytag, value, valuetype = tag
 *         else:
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2315; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = ((__pyx_t_5 == 3) != 0);
    if (__pyx_t_6) {

      /* "pysam/calignmentfile.pyx":2316
 *             valuetype = None
 *         elif len(tag) == 3:
 *             pytag, value, valuetype = tag             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError("malformatted tag: %s" % str(tag))
 */
      if ((likely(PyTuple_CheckExact(__pyx_v_tag))) || (PyList_CheckExact(__pyx_v_tag))) {
        PyObject* sequence = __pyx_v_tag;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 3)) {
          if (size > 3) __Pyx_RaiseTooManyValuesError(3);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
          __pyx_t_8 = PyTuple_GET_ITEM(sequence, 2); 
        } else {
          __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
          __pyx_t_8 = PyList_GET_ITEM(sequence, 2); 
        }
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_8);
        #else
        __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_8 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        #endif
      } else {
        Py_ssize_t index = -1;
        __pyx_t_10 = PyObject_GetIter(__pyx_v_tag); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_9 = Py_TYPE(__pyx_t_10)->tp_iternext;
        index = 0; __pyx_t_7 = __pyx_t_9(__pyx_t_10); if (unlikely(!__pyx_t_7)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        index = 1; __pyx_t_1 = __pyx_t_9(__pyx_t_10); if (unlikely(!__pyx_t_1)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_1);
        index = 2; __pyx_t_8 = __pyx_t_9(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_8);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_10), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L9_unpacking_done;
        __pyx_L8_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L9_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_pytag, __pyx_t_7);
      __pyx_t_7 = 0;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_1);
      __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_valuetype, __pyx_t_8);
      __pyx_t_8 = 0;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "pysam/calignmentfile.pyx":2318
 *             pytag, value, valuetype = tag
 *         else:
 *             raise ValueError("malformatted tag: %s" % str(tag))             # <<<<<<<<<<<<<<
 * 
 *         if not type(pytag) is bytes:
 */
      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_v_tag);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_tag);
      __Pyx_GIVEREF(__pyx_v_tag);
      __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_malformatted_tag_s, __pyx_t_1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2318; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L5:;

    /* "pysam/calignmentfile.pyx":2320
 *             raise ValueError("malformatted tag: %s" % str(tag))
 * 
 *         if not type(pytag) is bytes:             # <<<<<<<<<<<<<<
 *             pytag = pytag.encode('ascii')
 * 
 */
    __pyx_t_6 = (((PyObject *)Py_TYPE(__pyx_v_pytag)) != ((PyObject *)((PyObject*)(&PyBytes_Type))));
    __pyx_t_11 = (__pyx_t_6 != 0);
    if (__pyx_t_11) {

      /* "pysam/calignmentfile.pyx":2321
 * 
 *         if not type(pytag) is bytes:
 *             pytag = pytag.encode('ascii')             # <<<<<<<<<<<<<<
 * 
 *         datatype2format = {'c': 'b',
 */
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_pytag, __pyx_n_s_encode); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_tuple__75, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF_SET(__pyx_v_pytag, __pyx_t_1);
      __pyx_t_1 = 0;
      goto __pyx_L10;
    }
    __pyx_L10:;

    /* "pysam/calignmentfile.pyx":2323
 *             pytag = pytag.encode('ascii')
 * 
 *         datatype2format = {'c': 'b',             # <<<<<<<<<<<<<<
 *                            's': 'h',
 *                            'i': 'i',
 */
    __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_c, __pyx_n_s_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_s_2, __pyx_n_s_h) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_i, __pyx_n_s_i) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_C, __pyx_n_s_B) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_S, __pyx_n_s_H) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_I, __pyx_n_s_I) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_f, __pyx_n_s_f) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_A, __pyx_n_s_c) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2323; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF_SET(__pyx_v_datatype2format, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "pysam/calignmentfile.pyx":2332
 *                            'A': 'c',}
 * 
 *         t = type(value)             # <<<<<<<<<<<<<<
 *         if t is tuple or t is list:
 *             # binary tags are treated separately
 */
    __Pyx_INCREF(((PyObject *)Py_TYPE(__pyx_v_value)));
    __Pyx_XDECREF_SET(__pyx_v_t, ((PyObject*)((PyObject *)Py_TYPE(__pyx_v_value))));

    /* "pysam/calignmentfile.pyx":2333
 * 
 *         t = type(value)
 *         if t is tuple or t is list:             # <<<<<<<<<<<<<<
 *             # binary tags are treated separately
 *             if valuetype is None:
 */
    __pyx_t_6 = (__pyx_v_t == ((PyObject*)(&PyTuple_Type)));
    __pyx_t_12 = (__pyx_t_6 != 0);
    if (!__pyx_t_12) {
    } else {
      __pyx_t_11 = __pyx_t_12;
      goto __pyx_L12_bool_binop_done;
    }
    __pyx_t_12 = (__pyx_v_t == ((PyObject*)(&PyList_Type)));
    __pyx_t_6 = (__pyx_t_12 != 0);
    __pyx_t_11 = __pyx_t_6;
    __pyx_L12_bool_binop_done:;
    if (__pyx_t_11) {

      /* "pysam/calignmentfile.pyx":2335
 *         if t is tuple or t is list:
 *             # binary tags are treated separately
 *             if valuetype is None:             # <<<<<<<<<<<<<<
 *                 # automatically determine value type - first value
 *                 # determines type. If there is a mix of types, the
 */
      __pyx_t_11 = (__pyx_v_valuetype == Py_None);
      __pyx_t_6 = (__pyx_t_11 != 0);
      if (__pyx_t_6) {

        /* "pysam/calignmentfile.pyx":2339
 *                 # determines type. If there is a mix of types, the
 *                 # result is undefined.
 *                 valuetype = _get_value_type(min(value), max(value))             # <<<<<<<<<<<<<<
 * 
 *             if valuetype not in datatype2format:
 */
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_v_value);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_value);
        __Pyx_GIVEREF(__pyx_v_value);
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_min, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_v_value);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_value);
        __Pyx_GIVEREF(__pyx_v_value);
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_13.__pyx_n = 1;
        __pyx_t_13.maximum_value = __pyx_t_7;
        __pyx_t_1 = __pyx_f_5pysam_14calignmentfile__get_value_type(__pyx_t_8, &__pyx_t_13); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF_SET(__pyx_v_valuetype, __pyx_t_1);
        __pyx_t_1 = 0;
        goto __pyx_L14;
      }
      __pyx_L14:;

      /* "pysam/calignmentfile.pyx":2341
 *                 valuetype = _get_value_type(min(value), max(value))
 * 
 *             if valuetype not in datatype2format:             # <<<<<<<<<<<<<<
 *                 raise ValueError("invalid value type '%s'" % valuetype)
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype])
 */
      __pyx_t_6 = (__Pyx_PyDict_Contains(__pyx_v_valuetype, __pyx_v_datatype2format, Py_NE)); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = (__pyx_t_6 != 0);
      if (__pyx_t_11) {

        /* "pysam/calignmentfile.pyx":2342
 * 
 *             if valuetype not in datatype2format:
 *                 raise ValueError("invalid value type '%s'" % valuetype)             # <<<<<<<<<<<<<<
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype])
 * 
 */
        __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_invalid_value_type_s, __pyx_v_valuetype); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_1);
        __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_Raise(__pyx_t_1, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }

      /* "pysam/calignmentfile.pyx":2343
 *             if valuetype not in datatype2format:
 *                 raise ValueError("invalid value type '%s'" % valuetype)
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype])             # <<<<<<<<<<<<<<
 * 
 *             args.extend([pytag[:2],
 */
      __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_datatype2format, __pyx_v_valuetype); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __pyx_t_1 = 0;
      __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_2sccI_i_s, __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF_SET(__pyx_v_datafmt, ((PyObject*)__pyx_t_7));
      __pyx_t_7 = 0;

      /* "pysam/calignmentfile.pyx":2345
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype])
 * 
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          b"B",
 *                          valuetype,
 */
      __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__76, 0, 1, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);

      /* "pysam/calignmentfile.pyx":2348
 *                          b"B",
 *                          valuetype,
 *                          len(value)] + list(value))             # <<<<<<<<<<<<<<
 *             fmts.append(datafmt)
 * 
 */
      __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);

      /* "pysam/calignmentfile.pyx":2345
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype])
 * 
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          b"B",
 *                          valuetype,
 */
      __pyx_t_1 = PyList_New(4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_n_b_B);
      PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_b_B);
      __Pyx_GIVEREF(__pyx_n_b_B);
      __Pyx_INCREF(__pyx_v_valuetype);
      PyList_SET_ITEM(__pyx_t_1, 2, __pyx_v_valuetype);
      __Pyx_GIVEREF(__pyx_v_valuetype);
      PyList_SET_ITEM(__pyx_t_1, 3, __pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_8);
      __pyx_t_7 = 0;
      __pyx_t_8 = 0;

      /* "pysam/calignmentfile.pyx":2348
 *                          b"B",
 *                          valuetype,
 *                          len(value)] + list(value))             # <<<<<<<<<<<<<<
 *             fmts.append(datafmt)
 * 
 */
      __pyx_t_8 = PySequence_List(__pyx_v_value); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_7 = PyNumber_Add(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "pysam/calignmentfile.pyx":2345
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype])
 * 
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          b"B",
 *                          valuetype,
 */
      __pyx_t_14 = __Pyx_PyList_Extend(__pyx_v_args, __pyx_t_7); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pysam/calignmentfile.pyx":2349
 *                          valuetype,
 *                          len(value)] + list(value))
 *             fmts.append(datafmt)             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
      __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_fmts, __pyx_v_datafmt); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L11;
    }
    /*else*/ {

      /* "pysam/calignmentfile.pyx":2353
 *         else:
 * 
 *             if valuetype is None:             # <<<<<<<<<<<<<<
 *                 valuetype = _get_value_type(value)
 * 
 */
      __pyx_t_11 = (__pyx_v_valuetype == Py_None);
      __pyx_t_6 = (__pyx_t_11 != 0);
      if (__pyx_t_6) {

        /* "pysam/calignmentfile.pyx":2354
 * 
 *             if valuetype is None:
 *                 valuetype = _get_value_type(value)             # <<<<<<<<<<<<<<
 * 
 *             if valuetype == b"Z":
 */
        __pyx_t_7 = __pyx_f_5pysam_14calignmentfile__get_value_type(__pyx_v_value, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF_SET(__pyx_v_valuetype, __pyx_t_7);
        __pyx_t_7 = 0;
        goto __pyx_L16;
      }
      __pyx_L16:;

      /* "pysam/calignmentfile.pyx":2356
 *                 valuetype = _get_value_type(value)
 * 
 *             if valuetype == b"Z":             # <<<<<<<<<<<<<<
 *                 fmt = "2sc%is" % (len(value)+1)
 *             else:
 */
      __pyx_t_6 = (__Pyx_PyBytes_Equals(__pyx_v_valuetype, __pyx_n_b_Z, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      if (__pyx_t_6) {

        /* "pysam/calignmentfile.pyx":2357
 * 
 *             if valuetype == b"Z":
 *                 fmt = "2sc%is" % (len(value)+1)             # <<<<<<<<<<<<<<
 *             else:
 *                 fmt = "2sc%s" % datatype2format[valuetype]
 */
        __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_7 = PyInt_FromSsize_t((__pyx_t_5 + 1)); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_2sc_is, __pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2357; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF_SET(__pyx_v_fmt, __pyx_t_8);
        __pyx_t_8 = 0;
        goto __pyx_L17;
      }
      /*else*/ {

        /* "pysam/calignmentfile.pyx":2359
 *                 fmt = "2sc%is" % (len(value)+1)
 *             else:
 *                 fmt = "2sc%s" % datatype2format[valuetype]             # <<<<<<<<<<<<<<
 * 
 *             args.extend([pytag[:2],
 */
        __pyx_t_8 = __Pyx_PyDict_GetItem(__pyx_v_datatype2format, __pyx_v_valuetype); if (unlikely(__pyx_t_8 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2359; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_2sc_s, __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_XDECREF_SET(__pyx_v_fmt, __pyx_t_7);
        __pyx_t_7 = 0;
      }
      __pyx_L17:;

      /* "pysam/calignmentfile.pyx":2361
 *                 fmt = "2sc%s" % datatype2format[valuetype]
 * 
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          valuetype,
 *                          value])
 */
      __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_v_pytag, 0, 2, NULL, NULL, &__pyx_slice__77, 0, 1, 1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);

      /* "pysam/calignmentfile.pyx":2363
 *             args.extend([pytag[:2],
 *                          valuetype,
 *                          value])             # <<<<<<<<<<<<<<
 * 
 *             fmts.append(fmt)
 */
      __pyx_t_8 = PyList_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      PyList_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_v_valuetype);
      PyList_SET_ITEM(__pyx_t_8, 1, __pyx_v_valuetype);
      __Pyx_GIVEREF(__pyx_v_valuetype);
      __Pyx_INCREF(__pyx_v_value);
      PyList_SET_ITEM(__pyx_t_8, 2, __pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      __pyx_t_7 = 0;

      /* "pysam/calignmentfile.pyx":2361
 *                 fmt = "2sc%s" % datatype2format[valuetype]
 * 
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          valuetype,
 *                          value])
 */
      __pyx_t_14 = __Pyx_PyList_Extend(__pyx_v_args, __pyx_t_8); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "pysam/calignmentfile.pyx":2365
 *                          value])
 * 
 *             fmts.append(fmt)             # <<<<<<<<<<<<<<
 * 
 *     return "".join(fmts), args
 */
      __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_fmts, __pyx_v_fmt); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2365; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L11:;

    /* "pysam/calignmentfile.pyx":2310
 *     fmts, args = ["<"], []
 * 
 *     for tag in tags:             # <<<<<<<<<<<<<<
 * 
 *         if len(tag) == 2:
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":2367
 *             fmts.append(fmt)
 * 
 *     return "".join(fmts), args             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__7, __pyx_v_fmts); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2367; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_args);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_args);
  __Pyx_GIVEREF(__pyx_v_args);
  __pyx_t_2 = 0;
  __pyx_r = __pyx_t_8;
  __pyx_t_8 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2299
 * 
 * 
 * cdef inline _pack_tags(tags):             # <<<<<<<<<<<<<<
 *     """pack a list of tags. Each tag is a tuple of (tag, tuple).
 * 
 */

  /* 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_10);
  __Pyx_AddTraceback("pysam.calignmentfile._pack_tags", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fmts);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_tag);
  __Pyx_XDECREF(__pyx_v_pytag);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XDECREF(__pyx_v_valuetype);
  __Pyx_XDECREF(__pyx_v_datatype2format);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_datafmt);
  __Pyx_XDECREF(__pyx_v_fmt);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2390
 * 
 *     # Now only called when instances are created from Python
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         # see bam_init1
 *         self._delegate = <bam1_t*>calloc(1, sizeof(bam1_t))
 */

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

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment___init__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 2390);

  /* "pysam/calignmentfile.pyx":2392
 *     def __init__(self):
 *         # see bam_init1
 *         self._delegate = <bam1_t*>calloc(1, sizeof(bam1_t))             # <<<<<<<<<<<<<<
 *         # allocate some memory. If size is 0, calloc does not return a
 *         # pointer that can be passed to free() so allocate 40 bytes
 */
  __pyx_v_self->_delegate = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  /* "pysam/calignmentfile.pyx":2396
 *         # pointer that can be passed to free() so allocate 40 bytes
 *         # for a new read
 *         self._delegate.m_data = 40             # <<<<<<<<<<<<<<
 *         self._delegate.data = <uint8_t *>calloc(
 *             self._delegate.m_data, 1)
 */
  __pyx_v_self->_delegate->m_data = 40;

  /* "pysam/calignmentfile.pyx":2397
 *         # for a new read
 *         self._delegate.m_data = 40
 *         self._delegate.data = <uint8_t *>calloc(             # <<<<<<<<<<<<<<
 *             self._delegate.m_data, 1)
 *         self._delegate.l_data = 0
 */
  __pyx_v_self->_delegate->data = ((uint8_t *)calloc(__pyx_v_self->_delegate->m_data, 1));

  /* "pysam/calignmentfile.pyx":2399
 *         self._delegate.data = <uint8_t *>calloc(
 *             self._delegate.m_data, 1)
 *         self._delegate.l_data = 0             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
  __pyx_v_self->_delegate->l_data = 0;

  /* "pysam/calignmentfile.pyx":2390
 * 
 *     # Now only called when instances are created from Python
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         # see bam_init1
 *         self._delegate = <bam1_t*>calloc(1, sizeof(bam1_t))
 */

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

/* "pysam/calignmentfile.pyx":2401
 *         self._delegate.l_data = 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self._delegate)
 * 
 */

/* Python wrapper */
static void __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_2__dealloc__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static void __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_2__dealloc__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 2401);

  /* "pysam/calignmentfile.pyx":2402
 * 
 *     def __dealloc__(self):
 *         bam_destroy1(self._delegate)             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  bam_destroy1(__pyx_v_self->_delegate);

  /* "pysam/calignmentfile.pyx":2401
 *         self._delegate.l_data = 0
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         bam_destroy1(self._delegate)
 * 
 */

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

/* "pysam/calignmentfile.pyx":2404
 *         bam_destroy1(self._delegate)
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         """return string representation of alignment.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5__str__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_4__str__[] = "return string representation of alignment.\n\n        The representation is an approximate :term:`sam` format.\n\n        An aligned read might not be associated with a :term:`AlignmentFile`.\n        As a result :term:`tid` is shown instead of the reference name.\n\n        Similarly, the tags field is returned in its parsed state.\n        ";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_5pysam_14calignmentfile_14AlignedSegment_4__str__;
#endif
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4__str__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4__str__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 2404);

  /* "pysam/calignmentfile.pyx":2416
 *         # sam-parsing is done in sam.c/bam_format1_core which
 *         # requires a valid header.
 *         return "\t".join(map(str, (self.query_name,             # <<<<<<<<<<<<<<
 *                                    self.flag,
 *                                    self.reference_id,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/calignmentfile.pyx":2417
 *         # requires a valid header.
 *         return "\t".join(map(str, (self.query_name,
 *                                    self.flag,             # <<<<<<<<<<<<<<
 *                                    self.reference_id,
 *                                    self.reference_start,
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/calignmentfile.pyx":2418
 *         return "\t".join(map(str, (self.query_name,
 *                                    self.flag,
 *                                    self.reference_id,             # <<<<<<<<<<<<<<
 *                                    self.reference_start,
 *                                    self.mapping_quality,
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/calignmentfile.pyx":2419
 *                                    self.flag,
 *                                    self.reference_id,
 *                                    self.reference_start,             # <<<<<<<<<<<<<<
 *                                    self.mapping_quality,
 *                                    self.cigarstring,
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/calignmentfile.pyx":2420
 *                                    self.reference_id,
 *                                    self.reference_start,
 *                                    self.mapping_quality,             # <<<<<<<<<<<<<<
 *                                    self.cigarstring,
 *                                    self.next_reference_id,
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/calignmentfile.pyx":2421
 *                                    self.reference_start,
 *                                    self.mapping_quality,
 *                                    self.cigarstring,             # <<<<<<<<<<<<<<
 *                                    self.next_reference_id,
 *                                    self.next_reference_start,
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigarstring); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);

  /* "pysam/calignmentfile.pyx":2422
 *                                    self.mapping_quality,
 *                                    self.cigarstring,
 *                                    self.next_reference_id,             # <<<<<<<<<<<<<<
 *                                    self.next_reference_start,
 *                                    self.query_alignment_length,
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);

  /* "pysam/calignmentfile.pyx":2423
 *                                    self.cigarstring,
 *                                    self.next_reference_id,
 *                                    self.next_reference_start,             # <<<<<<<<<<<<<<
 *                                    self.query_alignment_length,
 *                                    self.query_sequence,
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2423; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);

  /* "pysam/calignmentfile.pyx":2424
 *                                    self.next_reference_id,
 *                                    self.next_reference_start,
 *                                    self.query_alignment_length,             # <<<<<<<<<<<<<<
 *                                    self.query_sequence,
 *                                    self.query_qualities,
 */
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);

  /* "pysam/calignmentfile.pyx":2425
 *                                    self.next_reference_start,
 *                                    self.query_alignment_length,
 *                                    self.query_sequence,             # <<<<<<<<<<<<<<
 *                                    self.query_qualities,
 *                                    self.tags)))
 */
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_10);

  /* "pysam/calignmentfile.pyx":2426
 *                                    self.query_alignment_length,
 *                                    self.query_sequence,
 *                                    self.query_qualities,             # <<<<<<<<<<<<<<
 *                                    self.tags)))
 * 
 */
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2426; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);

  /* "pysam/calignmentfile.pyx":2427
 *                                    self.query_sequence,
 *                                    self.query_qualities,
 *                                    self.tags)))             # <<<<<<<<<<<<<<
 * 
 *     def compare(self, AlignedSegment other):
 */
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tags); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2427; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_12);

  /* "pysam/calignmentfile.pyx":2416
 *         # sam-parsing is done in sam.c/bam_format1_core which
 *         # requires a valid header.
 *         return "\t".join(map(str, (self.query_name,             # <<<<<<<<<<<<<<
 *                                    self.flag,
 *                                    self.reference_id,
 */
  __pyx_t_13 = PyTuple_New(12); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_13);
  PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_13, 4, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_13, 5, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_13, 6, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_13, 7, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_13, 8, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_13, 9, __pyx_t_10);
  __Pyx_GIVEREF(__pyx_t_10);
  PyTuple_SET_ITEM(__pyx_t_13, 10, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_11);
  PyTuple_SET_ITEM(__pyx_t_13, 11, __pyx_t_12);
  __Pyx_GIVEREF(__pyx_t_12);
  __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_t_9 = 0;
  __pyx_t_10 = 0;
  __pyx_t_11 = 0;
  __pyx_t_12 = 0;
  __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_12, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_13);
  __Pyx_GIVEREF(__pyx_t_13);
  __pyx_t_13 = 0;
  __pyx_t_13 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_12, NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __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__46, __pyx_t_13); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __pyx_r = __pyx_t_12;
  __pyx_t_12 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2404
 *         bam_destroy1(self._delegate)
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         """return string representation of alignment.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2429
 *                                    self.tags)))
 * 
 *     def compare(self, AlignedSegment other):             # <<<<<<<<<<<<<<
 *         '''return -1,0,1, if contents in this are binary
 *         <,=,> to *other*
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_7compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_6compare[] = "AlignedSegment.compare(self, AlignedSegment other)\nreturn -1,0,1, if contents in this are binary\n        <,=,> to *other*\n\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_7compare(PyObject *__pyx_v_self, PyObject *__pyx_v_other) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("compare (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_14calignmentfile_AlignedSegment, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2429; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_6compare(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_other));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_6compare(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_other) {
  int __pyx_v_retval;
  bam1_t *__pyx_v_t;
  bam1_t *__pyx_v_o;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("compare", 0);
  __Pyx_TraceCall("compare", __pyx_f[0], 2429);

  /* "pysam/calignmentfile.pyx":2439
 *         cdef bam1_t *o
 * 
 *         t = self._delegate             # <<<<<<<<<<<<<<
 *         o = other._delegate
 * 
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_t = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2440
 * 
 *         t = self._delegate
 *         o = other._delegate             # <<<<<<<<<<<<<<
 * 
 *         # uncomment for debugging purposes
 */
  __pyx_t_1 = __pyx_v_other->_delegate;
  __pyx_v_o = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2452
 * 
 *         # Fast-path test for object identity
 *         if t == o:             # <<<<<<<<<<<<<<
 *             return 0
 * 
 */
  __pyx_t_2 = ((__pyx_v_t == __pyx_v_o) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2453
 *         # Fast-path test for object identity
 *         if t == o:
 *             return 0             # <<<<<<<<<<<<<<
 * 
 *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_int_0);
    __pyx_r = __pyx_int_0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2455
 *             return 0
 * 
 *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))             # <<<<<<<<<<<<<<
 * 
 *         if retval:
 */
  __pyx_v_retval = memcmp((&__pyx_v_t->core), (&__pyx_v_o->core), (sizeof(bam1_core_t)));

  /* "pysam/calignmentfile.pyx":2457
 *         retval = memcmp(&t.core, &o.core, sizeof(bam1_core_t))
 * 
 *         if retval:             # <<<<<<<<<<<<<<
 *             return retval
 *         # cmp(t.l_data, o.l_data)
 */
  __pyx_t_2 = (__pyx_v_retval != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2458
 * 
 *         if retval:
 *             return retval             # <<<<<<<<<<<<<<
 *         # cmp(t.l_data, o.l_data)
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2460
 *             return retval
 *         # cmp(t.l_data, o.l_data)
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data)             # <<<<<<<<<<<<<<
 *         if retval:
 *             return retval
 */
  __pyx_v_retval = ((__pyx_v_t->l_data > __pyx_v_o->l_data) - (__pyx_v_t->l_data < __pyx_v_o->l_data));

  /* "pysam/calignmentfile.pyx":2461
 *         # cmp(t.l_data, o.l_data)
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data)
 *         if retval:             # <<<<<<<<<<<<<<
 *             return retval
 *         return memcmp(t.data, o.data, t.l_data)
 */
  __pyx_t_2 = (__pyx_v_retval != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2462
 *         retval = (t.l_data > o.l_data) - (t.l_data < o.l_data)
 *         if retval:
 *             return retval             # <<<<<<<<<<<<<<
 *         return memcmp(t.data, o.data, t.l_data)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_retval); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2463
 *         if retval:
 *             return retval
 *         return memcmp(t.data, o.data, t.l_data)             # <<<<<<<<<<<<<<
 * 
 *     def __richcmp__(self, AlignedSegment other, int op):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyInt_From_int(memcmp(__pyx_v_t->data, __pyx_v_o->data, __pyx_v_t->l_data)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2429
 *                                    self.tags)))
 * 
 *     def compare(self, AlignedSegment other):             # <<<<<<<<<<<<<<
 *         '''return -1,0,1, if contents in this are binary
 *         <,=,> to *other*
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.compare", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2465
 *         return memcmp(t.data, o.data, t.l_data)
 * 
 *     def __richcmp__(self, AlignedSegment other, int op):             # <<<<<<<<<<<<<<
 *         if op == 2:  # == operator
 *             return self.compare(other) == 0
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) {
  CYTHON_UNUSED int __pyx_lineno = 0;
  CYTHON_UNUSED const char *__pyx_filename = NULL;
  CYTHON_UNUSED int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5pysam_14calignmentfile_AlignedSegment, 1, "other", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2465; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8__richcmp__(((PyObject *)__pyx_v_self), ((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_other), ((int)__pyx_v_op));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8__richcmp__(PyObject *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_other, int __pyx_v_op) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__richcmp__", 0);
  __Pyx_TraceCall("__richcmp__", __pyx_f[0], 2465);

  /* "pysam/calignmentfile.pyx":2468
 *         if op == 2:  # == operator
 *             return self.compare(other) == 0
 *         elif op == 3:  # != operator             # <<<<<<<<<<<<<<
 *             return self.compare(other) != 0
 *         else:
 */
  switch (__pyx_v_op) {

    /* "pysam/calignmentfile.pyx":2466
 * 
 *     def __richcmp__(self, AlignedSegment other, int op):
 *         if op == 2:  # == operator             # <<<<<<<<<<<<<<
 *             return self.compare(other) == 0
 *         elif op == 3:  # != operator
 */
    case 2:

    /* "pysam/calignmentfile.pyx":2467
 *     def __richcmp__(self, AlignedSegment other, int op):
 *         if op == 2:  # == operator
 *             return self.compare(other) == 0             # <<<<<<<<<<<<<<
 *         elif op == 3:  # != operator
 *             return self.compare(other) != 0
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_compare); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && 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);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_other));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)__pyx_v_other));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_0, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
    break;

    /* "pysam/calignmentfile.pyx":2468
 *         if op == 2:  # == operator
 *             return self.compare(other) == 0
 *         elif op == 3:  # != operator             # <<<<<<<<<<<<<<
 *             return self.compare(other) != 0
 *         else:
 */
    case 3:

    /* "pysam/calignmentfile.pyx":2469
 *             return self.compare(other) == 0
 *         elif op == 3:  # != operator
 *             return self.compare(other) != 0             # <<<<<<<<<<<<<<
 *         else:
 *             return NotImplemented
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_compare); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && 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);
      }
    }
    if (!__pyx_t_4) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)__pyx_v_other)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_INCREF(((PyObject *)__pyx_v_other));
      PyTuple_SET_ITEM(__pyx_t_3, 0+1, ((PyObject *)__pyx_v_other));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_other));
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2469; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
    break;
    default:

    /* "pysam/calignmentfile.pyx":2471
 *             return self.compare(other) != 0
 *         else:
 *             return NotImplemented             # <<<<<<<<<<<<<<
 * 
 *     # Disabled so long as __cmp__ is a special method
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_builtin_NotImplemented);
    __pyx_r = __pyx_builtin_NotImplemented;
    goto __pyx_L0;
    break;
  }

  /* "pysam/calignmentfile.pyx":2465
 *         return memcmp(t.data, o.data, t.l_data)
 * 
 *     def __richcmp__(self, AlignedSegment other, int op):             # <<<<<<<<<<<<<<
 *         if op == 2:  # == operator
 *             return self.compare(other) == 0
 */

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

/* "pysam/calignmentfile.pyx":2474
 * 
 *     # Disabled so long as __cmp__ is a special method
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         cdef bam1_t * src
 *         src = self._delegate
 */

/* Python wrapper */
static Py_hash_t __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11__hash__(PyObject *__pyx_v_self); /*proto*/
static Py_hash_t __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11__hash__(PyObject *__pyx_v_self) {
  Py_hash_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10__hash__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static Py_hash_t __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10__hash__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_hash_value;
  Py_hash_t __pyx_r;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__hash__", 0);
  __Pyx_TraceCall("__hash__", __pyx_f[0], 2474);

  /* "pysam/calignmentfile.pyx":2476
 *     def __hash__(self):
 *         cdef bam1_t * src
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         # shift and xor values in the core structure
 *         # make sure tid and mtid are shifted by different amounts
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2485
 *             src.core.flag ^ \
 *             src.core.isize << 24 ^ \
 *             src.core.mtid << 16 ^ \             # <<<<<<<<<<<<<<
 *             src.core.mpos << 8
 * 
 */
  __pyx_v_hash_value = (((((((__pyx_v_src->core.tid << 24) ^ (__pyx_v_src->core.pos << 16)) ^ (__pyx_v_src->core.qual << 8)) ^ __pyx_v_src->core.flag) ^ (__pyx_v_src->core.isize << 24)) ^ (__pyx_v_src->core.mtid << 16)) ^ (__pyx_v_src->core.mpos << 8));

  /* "pysam/calignmentfile.pyx":2488
 *             src.core.mpos << 8
 * 
 *         return hash_value             # <<<<<<<<<<<<<<
 * 
 *     ########################################################
 */
  __pyx_r = __pyx_v_hash_value;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2474
 * 
 *     # Disabled so long as __cmp__ is a special method
 *     def __hash__(self):             # <<<<<<<<<<<<<<
 *         cdef bam1_t * src
 *         src = self._delegate
 */

  /* function exit code */
  __pyx_L0:;
  if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2494
 *     property query_name:
 *         """the query template name (None if not present)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10query_name_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10query_name_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10query_name___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10query_name___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2494);

  /* "pysam/calignmentfile.pyx":2496
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if pysam_get_l_qname(src) == 0:
 *                 return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2497
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if pysam_get_l_qname(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return _charptr_to_str(<char *>pysam_bam_get_qname(src))
 */
  __pyx_t_2 = ((pysam_get_l_qname(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2498
 *             src = self._delegate
 *             if pysam_get_l_qname(src) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             return _charptr_to_str(<char *>pysam_bam_get_qname(src))
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2499
 *             if pysam_get_l_qname(src) == 0:
 *                 return None
 *             return _charptr_to_str(<char *>pysam_bam_get_qname(src))             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, qname):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __pyx_f_5pysam_14calignmentfile__charptr_to_str(((char *)pysam_bam_get_qname(__pyx_v_src))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2494
 *     property query_name:
 *         """the query template name (None if not present)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.query_name.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2501
 *             return _charptr_to_str(<char *>pysam_bam_get_qname(src))
 * 
 *         def __set__(self, qname):             # <<<<<<<<<<<<<<
 *             if qname is None or len(qname) == 0:
 *                 return
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10query_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10query_name_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qname) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10query_name_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qname));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10query_name_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qname) {
  bam1_t *__pyx_v_src;
  int __pyx_v_l;
  char *__pyx_v_p;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  bam1_t *__pyx_t_6;
  char const *__pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2501);
  __Pyx_INCREF(__pyx_v_qname);

  /* "pysam/calignmentfile.pyx":2502
 * 
 *         def __set__(self, qname):
 *             if qname is None or len(qname) == 0:             # <<<<<<<<<<<<<<
 *                 return
 *             qname = _forceBytes(qname)
 */
  __pyx_t_2 = (__pyx_v_qname == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = ((__pyx_t_4 == 0) != 0);
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":2503
 *         def __set__(self, qname):
 *             if qname is None or len(qname) == 0:
 *                 return             # <<<<<<<<<<<<<<
 *             qname = _forceBytes(qname)
 *             cdef bam1_t * src
 */
    __pyx_r = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2504
 *             if qname is None or len(qname) == 0:
 *                 return
 *             qname = _forceBytes(qname)             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef int l
 */
  __pyx_t_5 = __pyx_f_5pysam_14calignmentfile__forceBytes(__pyx_v_qname); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF_SET(__pyx_v_qname, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "pysam/calignmentfile.pyx":2509
 *             cdef char * p
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             p = pysam_bam_get_qname(src)
 * 
 */
  __pyx_t_6 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_6;

  /* "pysam/calignmentfile.pyx":2510
 * 
 *             src = self._delegate
 *             p = pysam_bam_get_qname(src)             # <<<<<<<<<<<<<<
 * 
 *             # the qname is \0 terminated
 */
  __pyx_v_p = pysam_bam_get_qname(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":2513
 * 
 *             # the qname is \0 terminated
 *             l = len(qname) + 1             # <<<<<<<<<<<<<<
 *             pysam_bam_update(src,
 *                              pysam_get_l_qname(src),
 */
  __pyx_t_4 = PyObject_Length(__pyx_v_qname); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2513; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_l = (__pyx_t_4 + 1);

  /* "pysam/calignmentfile.pyx":2514
 *             # the qname is \0 terminated
 *             l = len(qname) + 1
 *             pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                              pysam_get_l_qname(src),
 *                              l,
 */
  pysam_bam_update(__pyx_v_src, pysam_get_l_qname(__pyx_v_src), __pyx_v_l, ((uint8_t *)__pyx_v_p));

  /* "pysam/calignmentfile.pyx":2520
 * 
 * 
 *             pysam_set_l_qname(src, l)             # <<<<<<<<<<<<<<
 * 
 *             # re-acquire pointer to location in memory
 */
  pysam_set_l_qname(__pyx_v_src, __pyx_v_l);

  /* "pysam/calignmentfile.pyx":2524
 *             # re-acquire pointer to location in memory
 *             # as it might have moved
 *             p = pysam_bam_get_qname(src)             # <<<<<<<<<<<<<<
 * 
 *             strncpy(p, qname, l)
 */
  __pyx_v_p = pysam_bam_get_qname(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":2526
 *             p = pysam_bam_get_qname(src)
 * 
 *             strncpy(p, qname, l)             # <<<<<<<<<<<<<<
 * 
 *     property flag:
 */
  __pyx_t_7 = __Pyx_PyObject_AsString(__pyx_v_qname); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  strncpy(__pyx_v_p, __pyx_t_7, __pyx_v_l);

  /* "pysam/calignmentfile.pyx":2501
 *             return _charptr_to_str(<char *>pysam_bam_get_qname(src))
 * 
 *         def __set__(self, qname):             # <<<<<<<<<<<<<<
 *             if qname is None or len(qname) == 0:
 *                 return
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.query_name.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_qname);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2530
 *     property flag:
 *         """properties flag"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4flag_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4flag_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4flag___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2531
 *         """properties flag"""
 *         def __get__(self):
 *             return pysam_get_flag(self._delegate)             # <<<<<<<<<<<<<<
 *         def __set__(self, flag):
 *             pysam_set_flag(self._delegate, flag)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint16_t(pysam_get_flag(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2530
 *     property flag:
 *         """properties flag"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):
 */

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

/* "pysam/calignmentfile.pyx":2532
 *         def __get__(self):
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):             # <<<<<<<<<<<<<<
 *             pysam_set_flag(self._delegate, flag)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4flag_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_flag) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4flag_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_flag));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4flag_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_flag) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2532);

  /* "pysam/calignmentfile.pyx":2533
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):
 *             pysam_set_flag(self._delegate, flag)             # <<<<<<<<<<<<<<
 * 
 *     property reference_id:
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_flag); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_set_flag(__pyx_v_self->_delegate, __pyx_t_1);

  /* "pysam/calignmentfile.pyx":2532
 *         def __get__(self):
 *             return pysam_get_flag(self._delegate)
 *         def __set__(self, flag):             # <<<<<<<<<<<<<<
 *             pysam_set_flag(self._delegate, flag)
 * 
 */

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

/* "pysam/calignmentfile.pyx":2546
 * 
 *         """
 *         def __get__(self): return self._delegate.core.tid             # <<<<<<<<<<<<<<
 *         def __set__(self, tid): self._delegate.core.tid = tid
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12reference_id_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12reference_id___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12reference_id___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2546);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":2547
 *         """
 *         def __get__(self): return self._delegate.core.tid
 *         def __set__(self, tid): self._delegate.core.tid = tid             # <<<<<<<<<<<<<<
 * 
 *     property reference_start:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12reference_id_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tid));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12reference_id_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2547);
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_tid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2547; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.tid = __pyx_t_1;

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

/* "pysam/calignmentfile.pyx":2551
 *     property reference_start:
 *         """0-based leftmost coordinate"""
 *         def __get__(self): return self._delegate.core.pos             # <<<<<<<<<<<<<<
 *         def __set__(self, pos):
 *             ## setting the position requires updating the "bin" attribute
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15reference_start_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15reference_start_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15reference_start___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15reference_start___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2551);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":2552
 *         """0-based leftmost coordinate"""
 *         def __get__(self): return self._delegate.core.pos
 *         def __set__(self, pos):             # <<<<<<<<<<<<<<
 *             ## setting the position requires updating the "bin" attribute
 *             cdef bam1_t * src
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_pos) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15reference_start_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_pos));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15reference_start_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_pos) {
  bam1_t *__pyx_v_src;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int32_t __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2552);

  /* "pysam/calignmentfile.pyx":2555
 *             ## setting the position requires updating the "bin" attribute
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             src.core.pos = pos
 *             if pysam_get_n_cigar(src):
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2556
 *             cdef bam1_t * src
 *             src = self._delegate
 *             src.core.pos = pos             # <<<<<<<<<<<<<<
 *             if pysam_get_n_cigar(src):
 *                 pysam_set_bin(src,
 */
  __pyx_t_2 = __Pyx_PyInt_As_int32_t(__pyx_v_pos); if (unlikely((__pyx_t_2 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_src->core.pos = __pyx_t_2;

  /* "pysam/calignmentfile.pyx":2557
 *             src = self._delegate
 *             src.core.pos = pos
 *             if pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *                 pysam_set_bin(src,
 *                               hts_reg2bin(
 */
  __pyx_t_3 = (pysam_get_n_cigar(__pyx_v_src) != 0);
  if (__pyx_t_3) {

    /* "pysam/calignmentfile.pyx":2558
 *             src.core.pos = pos
 *             if pysam_get_n_cigar(src):
 *                 pysam_set_bin(src,             # <<<<<<<<<<<<<<
 *                               hts_reg2bin(
 *                                   src.core.pos,
 */
    pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, bam_endpos(__pyx_v_src), 14, 5));
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":2565
 *                                   5))
 *             else:
 *                 pysam_set_bin(src,             # <<<<<<<<<<<<<<
 *                               hts_reg2bin(
 *                                   src.core.pos,
 */
    pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, (__pyx_v_src->core.pos + 1), 14, 5));
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":2552
 *         """0-based leftmost coordinate"""
 *         def __get__(self): return self._delegate.core.pos
 *         def __set__(self, pos):             # <<<<<<<<<<<<<<
 *             ## setting the position requires updating the "bin" attribute
 *             cdef bam1_t * src
 */

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

/* "pysam/calignmentfile.pyx":2574
 *     property mapping_quality:
 *         """mapping quality"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mapping_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mapping_quality_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15mapping_quality___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2575
 *         """mapping quality"""
 *         def __get__(self):
 *             return pysam_get_qual(self._delegate)             # <<<<<<<<<<<<<<
 *         def __set__(self, qual):
 *             pysam_set_qual(self._delegate, qual)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint8_t(pysam_get_qual(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2574
 *     property mapping_quality:
 *         """mapping quality"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):
 */

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

/* "pysam/calignmentfile.pyx":2576
 *         def __get__(self):
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):             # <<<<<<<<<<<<<<
 *             pysam_set_qual(self._delegate, qual)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mapping_quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mapping_quality_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15mapping_quality_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qual));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15mapping_quality_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint8_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2576);

  /* "pysam/calignmentfile.pyx":2577
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):
 *             pysam_set_qual(self._delegate, qual)             # <<<<<<<<<<<<<<
 * 
 *     property cigarstring:
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint8_t(__pyx_v_qual); if (unlikely((__pyx_t_1 == (uint8_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_set_qual(__pyx_v_self->_delegate, __pyx_t_1);

  /* "pysam/calignmentfile.pyx":2576
 *         def __get__(self):
 *             return pysam_get_qual(self._delegate)
 *         def __set__(self, qual):             # <<<<<<<<<<<<<<
 *             pysam_set_qual(self._delegate, qual)
 * 
 */

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

/* "pysam/calignmentfile.pyx":2596
 *         empty string.
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             c = self.cigartuples
 *             if c is None:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigarstring_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigarstring_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigarstring___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigarstring___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_v_c = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_y = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  Py_ssize_t __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2596);

  /* "pysam/calignmentfile.pyx":2597
 *         '''
 *         def __get__(self):
 *             c = self.cigartuples             # <<<<<<<<<<<<<<
 *             if c is None:
 *                 return None
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_c = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":2598
 *         def __get__(self):
 *             c = self.cigartuples
 *             if c is None:             # <<<<<<<<<<<<<<
 *                 return None
 *             # reverse order
 */
  __pyx_t_2 = (__pyx_v_c == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysam/calignmentfile.pyx":2599
 *             c = self.cigartuples
 *             if c is None:
 *                 return None             # <<<<<<<<<<<<<<
 *             # reverse order
 *             else:
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":2602
 *             # reverse order
 *             else:
 *                 return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, cigar):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (likely(PyList_CheckExact(__pyx_v_c)) || PyTuple_CheckExact(__pyx_v_c)) {
      __pyx_t_4 = __pyx_v_c; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_c); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_4))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        }
      } else {
        __pyx_t_7 = __pyx_t_6(__pyx_t_4);
        if (unlikely(!__pyx_t_7)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_7);
      }
      if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
        PyObject* sequence = __pyx_t_7;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_9);
        #else
        __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        #endif
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
        index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_8);
        index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_9);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_11 = NULL;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        goto __pyx_L7_unpacking_done;
        __pyx_L6_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_11 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L7_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_8);
      __pyx_t_8 = 0;
      __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_9);
      __pyx_t_9 = 0;
      __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_v_x); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_7 = __Pyx_PyInt_From_char((__pyx_v_5pysam_14calignmentfile_CODE2CIGAR[__pyx_t_12])); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_INCREF(__pyx_v_y);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_y);
      __Pyx_GIVEREF(__pyx_v_y);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_i_c, __pyx_t_9); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_7))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyString_Join(__pyx_kp_s__7, __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2596
 *         empty string.
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             c = self.cigartuples
 *             if c is None:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.cigarstring.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_c);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_y);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2604
 *                 return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])
 * 
 *         def __set__(self, cigar):             # <<<<<<<<<<<<<<
 *             if cigar is None or len(cigar) == 0:
 *                 self.cigartuples = []
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigarstring_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_cigar) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigarstring_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_cigar));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigarstring_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_cigar) {
  PyObject *__pyx_v_parts = NULL;
  PyObject *__pyx_v_x = NULL;
  PyObject *__pyx_v_y = NULL;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  Py_ssize_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)(PyObject *);
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *(*__pyx_t_12)(PyObject *);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2604);

  /* "pysam/calignmentfile.pyx":2605
 * 
 *         def __set__(self, cigar):
 *             if cigar is None or len(cigar) == 0:             # <<<<<<<<<<<<<<
 *                 self.cigartuples = []
 *             else:
 */
  __pyx_t_2 = (__pyx_v_cigar == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_1 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = PyObject_Length(__pyx_v_cigar); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2605; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = ((__pyx_t_4 == 0) != 0);
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":2606
 *         def __set__(self, cigar):
 *             if cigar is None or len(cigar) == 0:
 *                 self.cigartuples = []             # <<<<<<<<<<<<<<
 *             else:
 *                 parts = CIGAR_REGEX.findall(cigar)
 */
    __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":2608
 *                 self.cigartuples = []
 *             else:
 *                 parts = CIGAR_REGEX.findall(cigar)             # <<<<<<<<<<<<<<
 *                 # reverse order
 *                 self.cigartuples = [(CIGAR2CODE[ord(y)], int(x)) for x,y in parts]
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR_REGEX); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_findall); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_cigar); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_INCREF(__pyx_v_cigar);
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_cigar);
      __Pyx_GIVEREF(__pyx_v_cigar);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_parts = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "pysam/calignmentfile.pyx":2610
 *                 parts = CIGAR_REGEX.findall(cigar)
 *                 # reverse order
 *                 self.cigartuples = [(CIGAR2CODE[ord(y)], int(x)) for x,y in parts]             # <<<<<<<<<<<<<<
 * 
 *     # TODO
 */
    __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    if (likely(PyList_CheckExact(__pyx_v_parts)) || PyTuple_CheckExact(__pyx_v_parts)) {
      __pyx_t_7 = __pyx_v_parts; __Pyx_INCREF(__pyx_t_7); __pyx_t_4 = 0;
      __pyx_t_9 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_v_parts); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    for (;;) {
      if (likely(!__pyx_t_9)) {
        if (likely(PyList_CheckExact(__pyx_t_7))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_4); __Pyx_INCREF(__pyx_t_8); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_COMPILING_IN_CPYTHON
          __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_4); __Pyx_INCREF(__pyx_t_8); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #else
          __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          #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(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __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;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 2)) {
          if (size > 2) __Pyx_RaiseTooManyValuesError(2);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_10);
        #else
        __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        #endif
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_11 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext;
        index = 0; __pyx_t_6 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_6)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L8_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_10);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_12 = NULL;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        goto __pyx_L9_unpacking_done;
        __pyx_L8_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_12 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L9_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_x, __pyx_t_6);
      __pyx_t_6 = 0;
      __Pyx_XDECREF_SET(__pyx_v_y, __pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_CIGAR2CODE); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_v_y);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_y);
      __Pyx_GIVEREF(__pyx_v_y);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ord, __pyx_t_10, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = PyObject_GetItem(__pyx_t_8, __pyx_t_6); if (unlikely(__pyx_t_10 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyNumber_Int(__pyx_v_x); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_10 = 0;
      __pyx_t_6 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_8))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2610; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":2604
 *                 return "".join([ "%i%c" % (y,CODE2CIGAR[x]) for x,y in c])
 * 
 *         def __set__(self, cigar):             # <<<<<<<<<<<<<<
 *             if cigar is None or len(cigar) == 0:
 *                 self.cigartuples = []
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.cigarstring.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_parts);
  __Pyx_XDECREF(__pyx_v_x);
  __Pyx_XDECREF(__pyx_v_y);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2618
 *     property next_reference_id:
 *         """the :term:`reference` id of the mate/next read."""
 *         def __get__(self): return self._delegate.core.mtid             # <<<<<<<<<<<<<<
 *         def __set__(self, mtid):
 *             self._delegate.core.mtid = mtid
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2618);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mtid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2618; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":2619
 *         """the :term:`reference` id of the mate/next read."""
 *         def __get__(self): return self._delegate.core.mtid
 *         def __set__(self, mtid):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mtid = mtid
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mtid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_mtid));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mtid) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2619);

  /* "pysam/calignmentfile.pyx":2620
 *         def __get__(self): return self._delegate.core.mtid
 *         def __set__(self, mtid):
 *             self._delegate.core.mtid = mtid             # <<<<<<<<<<<<<<
 * 
 *     property next_reference_start:
 */
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_mtid); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2620; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.mtid = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2619
 *         """the :term:`reference` id of the mate/next read."""
 *         def __get__(self): return self._delegate.core.mtid
 *         def __set__(self, mtid):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mtid = mtid
 * 
 */

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

/* "pysam/calignmentfile.pyx":2624
 *     property next_reference_start:
 *         """the position of the mate/next read."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_20next_reference_start_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_20next_reference_start_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_20next_reference_start___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2625
 *         """the position of the mate/next read."""
 *         def __get__(self):
 *             return self._delegate.core.mpos             # <<<<<<<<<<<<<<
 *         def __set__(self, mpos):
 *             self._delegate.core.mpos = mpos
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.mpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2625; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2624
 *     property next_reference_start:
 *         """the position of the mate/next read."""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 */

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

/* "pysam/calignmentfile.pyx":2626
 *         def __get__(self):
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mpos = mpos
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_20next_reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_20next_reference_start_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_mpos) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_20next_reference_start_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_mpos));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_20next_reference_start_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_mpos) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2626);

  /* "pysam/calignmentfile.pyx":2627
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):
 *             self._delegate.core.mpos = mpos             # <<<<<<<<<<<<<<
 * 
 *     property query_length:
 */
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_mpos); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2627; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.mpos = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2626
 *         def __get__(self):
 *             return self._delegate.core.mpos
 *         def __set__(self, mpos):             # <<<<<<<<<<<<<<
 *             self._delegate.core.mpos = mpos
 * 
 */

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

/* "pysam/calignmentfile.pyx":2647
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.l_qseq
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12query_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12query_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12query_length___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2648
 *         """
 *         def __get__(self):
 *             return self._delegate.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *     property template_length:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.l_qseq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2647
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.l_qseq
 * 
 */

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

/* "pysam/calignmentfile.pyx":2652
 *     property template_length:
 *         """the observed query template length"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15template_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15template_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15template_length___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2653
 *         """the observed query template length"""
 *         def __get__(self):
 *             return self._delegate.core.isize             # <<<<<<<<<<<<<<
 *         def __set__(self, isize):
 *             self._delegate.core.isize = isize
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_delegate->core.isize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2652
 *     property template_length:
 *         """the observed query template length"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 */

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

/* "pysam/calignmentfile.pyx":2654
 *         def __get__(self):
 *             return self._delegate.core.isize
 *         def __set__(self, isize):             # <<<<<<<<<<<<<<
 *             self._delegate.core.isize = isize
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15template_length_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15template_length_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_isize) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15template_length_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_isize));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15template_length_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_isize) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int32_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2654);

  /* "pysam/calignmentfile.pyx":2655
 *             return self._delegate.core.isize
 *         def __set__(self, isize):
 *             self._delegate.core.isize = isize             # <<<<<<<<<<<<<<
 * 
 *     property query_sequence:
 */
  __pyx_t_1 = __Pyx_PyInt_As_int32_t(__pyx_v_isize); if (unlikely((__pyx_t_1 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2655; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->_delegate->core.isize = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2654
 *         def __get__(self):
 *             return self._delegate.core.isize
 *         def __set__(self, isize):             # <<<<<<<<<<<<<<
 *             self._delegate.core.isize = isize
 * 
 */

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

/* "pysam/calignmentfile.pyx":2673
 *         sequence.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef char * s
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14query_sequence_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14query_sequence_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14query_sequence___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14query_sequence___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2673);

  /* "pysam/calignmentfile.pyx":2676
 *             cdef bam1_t * src
 *             cdef char * s
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0: return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2678
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0: return None             # <<<<<<<<<<<<<<
 * 
 *             return _getSequenceRange(src, 0, src.core.l_qseq)
 */
  __pyx_t_2 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_2) {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2680
 *             if src.core.l_qseq == 0: return None
 * 
 *             return _getSequenceRange(src, 0, src.core.l_qseq)             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, seq):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __pyx_f_5pysam_14calignmentfile__getSequenceRange(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2673
 *         sequence.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef char * s
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.query_sequence.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2682
 *             return _getSequenceRange(src, 0, src.core.l_qseq)
 * 
 *         def __set__(self, seq):             # <<<<<<<<<<<<<<
 *             # samtools manages sequence and quality length memory together
 *             # if no quality information is present, the first byte says 0xff.
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14query_sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14query_sequence_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_seq) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14query_sequence_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_seq));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14query_sequence_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_seq) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_p;
  char *__pyx_v_s;
  int __pyx_v_l;
  int __pyx_v_k;
  int __pyx_v_nbytes_new;
  int __pyx_v_nbytes_old;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  bam1_t *__pyx_t_4;
  int __pyx_t_5;
  char *__pyx_t_6;
  long __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2682);
  __Pyx_INCREF(__pyx_v_seq);

  /* "pysam/calignmentfile.pyx":2690
 *             cdef int l, k, nbytes_new, nbytes_old
 * 
 *             if seq == None:             # <<<<<<<<<<<<<<
 *                 l = 0
 *             else:
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_seq, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2691
 * 
 *             if seq == None:
 *                 l = 0             # <<<<<<<<<<<<<<
 *             else:
 *                 l = len(seq)
 */
    __pyx_v_l = 0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":2693
 *                 l = 0
 *             else:
 *                 l = len(seq)             # <<<<<<<<<<<<<<
 *                 seq = _forceBytes(seq)
 * 
 */
    __pyx_t_3 = PyObject_Length(__pyx_v_seq); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_l = __pyx_t_3;

    /* "pysam/calignmentfile.pyx":2694
 *             else:
 *                 l = len(seq)
 *                 seq = _forceBytes(seq)             # <<<<<<<<<<<<<<
 * 
 *             src = self._delegate
 */
    __pyx_t_1 = __pyx_f_5pysam_14calignmentfile__forceBytes(__pyx_v_seq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_seq, __pyx_t_1);
    __pyx_t_1 = 0;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":2696
 *                 seq = _forceBytes(seq)
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             # as the sequence is stored in half-bytes, the total length (sequence
 */
  __pyx_t_4 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_4;

  /* "pysam/calignmentfile.pyx":2700
 *             # as the sequence is stored in half-bytes, the total length (sequence
 *             # plus quality scores) is (l+1)/2 + l
 *             nbytes_new = (l + 1) / 2 + l             # <<<<<<<<<<<<<<
 *             nbytes_old = (src.core.l_qseq + 1) / 2 + src.core.l_qseq
 * 
 */
  __pyx_v_nbytes_new = (__Pyx_div_long((__pyx_v_l + 1), 2) + __pyx_v_l);

  /* "pysam/calignmentfile.pyx":2701
 *             # plus quality scores) is (l+1)/2 + l
 *             nbytes_new = (l + 1) / 2 + l
 *             nbytes_old = (src.core.l_qseq + 1) / 2 + src.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *             # acquire pointer to location in memory
 */
  __pyx_v_nbytes_old = (__Pyx_div_long((__pyx_v_src->core.l_qseq + 1), 2) + __pyx_v_src->core.l_qseq);

  /* "pysam/calignmentfile.pyx":2704
 * 
 *             # acquire pointer to location in memory
 *             p = pysam_bam_get_seq(src)             # <<<<<<<<<<<<<<
 *             src.core.l_qseq = l
 * 
 */
  __pyx_v_p = pysam_bam_get_seq(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":2705
 *             # acquire pointer to location in memory
 *             p = pysam_bam_get_seq(src)
 *             src.core.l_qseq = l             # <<<<<<<<<<<<<<
 * 
 *             # change length of data field
 */
  __pyx_v_src->core.l_qseq = __pyx_v_l;

  /* "pysam/calignmentfile.pyx":2708
 * 
 *             # change length of data field
 *             pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                              nbytes_old,
 *                              nbytes_new,
 */
  pysam_bam_update(__pyx_v_src, __pyx_v_nbytes_old, __pyx_v_nbytes_new, __pyx_v_p);

  /* "pysam/calignmentfile.pyx":2713
 *                              p)
 * 
 *             if l > 0:             # <<<<<<<<<<<<<<
 *                 # re-acquire pointer to location in memory
 *                 # as it might have moved
 */
  __pyx_t_2 = ((__pyx_v_l > 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2716
 *                 # re-acquire pointer to location in memory
 *                 # as it might have moved
 *                 p = pysam_bam_get_seq(src)             # <<<<<<<<<<<<<<
 *                 for k from 0 <= k < nbytes_new:
 *                     p[k] = 0
 */
    __pyx_v_p = pysam_bam_get_seq(__pyx_v_src);

    /* "pysam/calignmentfile.pyx":2717
 *                 # as it might have moved
 *                 p = pysam_bam_get_seq(src)
 *                 for k from 0 <= k < nbytes_new:             # <<<<<<<<<<<<<<
 *                     p[k] = 0
 *                 # convert to C string
 */
    __pyx_t_5 = __pyx_v_nbytes_new;
    for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

      /* "pysam/calignmentfile.pyx":2718
 *                 p = pysam_bam_get_seq(src)
 *                 for k from 0 <= k < nbytes_new:
 *                     p[k] = 0             # <<<<<<<<<<<<<<
 *                 # convert to C string
 *                 s = seq
 */
      (__pyx_v_p[__pyx_v_k]) = 0;
    }

    /* "pysam/calignmentfile.pyx":2720
 *                     p[k] = 0
 *                 # convert to C string
 *                 s = seq             # <<<<<<<<<<<<<<
 *                 for k from 0 <= k < l:
 *                     p[k/2] |= seq_nt16_table[<unsigned char>s[k]] << 4 * (1 - k % 2)
 */
    __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_seq); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_s = __pyx_t_6;

    /* "pysam/calignmentfile.pyx":2721
 *                 # convert to C string
 *                 s = seq
 *                 for k from 0 <= k < l:             # <<<<<<<<<<<<<<
 *                     p[k/2] |= seq_nt16_table[<unsigned char>s[k]] << 4 * (1 - k % 2)
 * 
 */
    __pyx_t_5 = __pyx_v_l;
    for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

      /* "pysam/calignmentfile.pyx":2722
 *                 s = seq
 *                 for k from 0 <= k < l:
 *                     p[k/2] |= seq_nt16_table[<unsigned char>s[k]] << 4 * (1 - k % 2)             # <<<<<<<<<<<<<<
 * 
 *                 # erase qualities
 */
      __pyx_t_7 = __Pyx_div_long(__pyx_v_k, 2);
      (__pyx_v_p[__pyx_t_7]) = ((__pyx_v_p[__pyx_t_7]) | ((seq_nt16_table[((unsigned char)(__pyx_v_s[__pyx_v_k]))]) << (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2)))));
    }

    /* "pysam/calignmentfile.pyx":2725
 * 
 *                 # erase qualities
 *                 p = pysam_bam_get_qual(src)             # <<<<<<<<<<<<<<
 *                 p[0] = 0xff
 * 
 */
    __pyx_v_p = pysam_bam_get_qual(__pyx_v_src);

    /* "pysam/calignmentfile.pyx":2726
 *                 # erase qualities
 *                 p = pysam_bam_get_qual(src)
 *                 p[0] = 0xff             # <<<<<<<<<<<<<<
 * 
 *     property query_qualities:
 */
    (__pyx_v_p[0]) = 0xff;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "pysam/calignmentfile.pyx":2682
 *             return _getSequenceRange(src, 0, src.core.l_qseq)
 * 
 *         def __set__(self, seq):             # <<<<<<<<<<<<<<
 *             # samtools manages sequence and quality length memory together
 *             # if no quality information is present, the first byte says 0xff.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.query_sequence.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_seq);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2745
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 * 
 *             cdef bam1_t * src
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15query_qualities_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15query_qualities_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15query_qualities___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15query_qualities___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2745);

  /* "pysam/calignmentfile.pyx":2750
 *             cdef char * q
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0:
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2752
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  __pyx_t_2 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2753
 * 
 *             if src.core.l_qseq == 0:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             return _getQualitiesRange(src, 0, src.core.l_qseq)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2755
 *                 return None
 * 
 *             return _getQualitiesRange(src, 0, src.core.l_qseq)             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, qual):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __pyx_f_5pysam_14calignmentfile__getQualitiesRange(__pyx_v_src, 0, __pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2745
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 * 
 *             cdef bam1_t * src
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.query_qualities.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2757
 *             return _getQualitiesRange(src, 0, src.core.l_qseq)
 * 
 *         def __set__(self, qual):             # <<<<<<<<<<<<<<
 *             # note that memory is already allocated via setting the sequence
 *             # hence length match of sequence and quality needs is checked.
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15query_qualities_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15query_qualities_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_qual) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15query_qualities_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_qual));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15query_qualities_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_qual) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_p;
  int __pyx_v_l;
  arrayobject *__pyx_v_result = 0;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2757);

  /* "pysam/calignmentfile.pyx":2764
 *             cdef int l
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             p = pysam_bam_get_qual(src)
 *             if qual is None or len(qual) == 0:
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2765
 * 
 *             src = self._delegate
 *             p = pysam_bam_get_qual(src)             # <<<<<<<<<<<<<<
 *             if qual is None or len(qual) == 0:
 *                 # if absent and there is a sequence: set to 0xff
 */
  __pyx_v_p = pysam_bam_get_qual(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":2766
 *             src = self._delegate
 *             p = pysam_bam_get_qual(src)
 *             if qual is None or len(qual) == 0:             # <<<<<<<<<<<<<<
 *                 # if absent and there is a sequence: set to 0xff
 *                 if src.core.l_qseq != 0:
 */
  __pyx_t_3 = (__pyx_v_qual == Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (!__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = ((__pyx_t_5 == 0) != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2768
 *             if qual is None or len(qual) == 0:
 *                 # if absent and there is a sequence: set to 0xff
 *                 if src.core.l_qseq != 0:             # <<<<<<<<<<<<<<
 *                     p[0] = 0xff
 *                 return
 */
    __pyx_t_2 = ((__pyx_v_src->core.l_qseq != 0) != 0);
    if (__pyx_t_2) {

      /* "pysam/calignmentfile.pyx":2769
 *                 # if absent and there is a sequence: set to 0xff
 *                 if src.core.l_qseq != 0:
 *                     p[0] = 0xff             # <<<<<<<<<<<<<<
 *                 return
 * 
 */
      (__pyx_v_p[0]) = 0xff;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysam/calignmentfile.pyx":2770
 *                 if src.core.l_qseq != 0:
 *                     p[0] = 0xff
 *                 return             # <<<<<<<<<<<<<<
 * 
 *             # check for length match
 */
    __pyx_r = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2773
 * 
 *             # check for length match
 *             l = len(qual)             # <<<<<<<<<<<<<<
 *             if src.core.l_qseq != l:
 *                 raise ValueError(
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_qual); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_l = __pyx_t_5;

  /* "pysam/calignmentfile.pyx":2774
 *             # check for length match
 *             l = len(qual)
 *             if src.core.l_qseq != l:             # <<<<<<<<<<<<<<
 *                 raise ValueError(
 *                     "quality and sequence mismatch: %i != %i" %
 */
  __pyx_t_2 = ((__pyx_v_src->core.l_qseq != __pyx_v_l) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2777
 *                 raise ValueError(
 *                     "quality and sequence mismatch: %i != %i" %
 *                     (l, src.core.l_qseq))             # <<<<<<<<<<<<<<
 * 
 *             # create a python array object filling it
 */
    __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_l); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyInt_From_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_6 = 0;
    __pyx_t_7 = 0;

    /* "pysam/calignmentfile.pyx":2776
 *             if src.core.l_qseq != l:
 *                 raise ValueError(
 *                     "quality and sequence mismatch: %i != %i" %             # <<<<<<<<<<<<<<
 *                     (l, src.core.l_qseq))
 * 
 */
    __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_quality_and_sequence_mismatch_i, __pyx_t_8); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2776; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "pysam/calignmentfile.pyx":2775
 *             l = len(qual)
 *             if src.core.l_qseq != l:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "quality and sequence mismatch: %i != %i" %
 *                     (l, src.core.l_qseq))
 */
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_Raise(__pyx_t_7, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":2784
 *             # NB: should avoid this copying if qual is
 *             # already of the correct type.
 *             cdef array.array result = array.array('B', qual)             # <<<<<<<<<<<<<<
 * 
 *             # copy data
 */
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_n_s_B);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_n_s_B);
  __Pyx_GIVEREF(__pyx_n_s_B);
  __Pyx_INCREF(__pyx_v_qual);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_qual);
  __Pyx_GIVEREF(__pyx_v_qual);
  __pyx_t_8 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_7cpython_5array_array)), __pyx_t_7, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_result = ((arrayobject *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "pysam/calignmentfile.pyx":2787
 * 
 *             # copy data
 *             memcpy(p, result.data.as_voidptr, l)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  memcpy(__pyx_v_p, __pyx_v_result->data.as_voidptr, __pyx_v_l);

  /* "pysam/calignmentfile.pyx":2757
 *             return _getQualitiesRange(src, 0, src.core.l_qseq)
 * 
 *         def __set__(self, qual):             # <<<<<<<<<<<<<<
 *             # note that memory is already allocated via setting the sequence
 *             # hence length match of sequence and quality needs is checked.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.query_qualities.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_result);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2792
 *     property bin:
 *         """properties bin"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3bin_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3bin_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3bin___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2793
 *         """properties bin"""
 *         def __get__(self):
 *             return pysam_get_bin(self._delegate)             # <<<<<<<<<<<<<<
 *         def __set__(self, bin):
 *             pysam_set_bin(self._delegate, bin)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint16_t(pysam_get_bin(__pyx_v_self->_delegate)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2793; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2792
 *     property bin:
 *         """properties bin"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):
 */

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

/* "pysam/calignmentfile.pyx":2794
 *         def __get__(self):
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):             # <<<<<<<<<<<<<<
 *             pysam_set_bin(self._delegate, bin)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3bin_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_bin) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3bin_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_bin));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3bin_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_bin) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2794);

  /* "pysam/calignmentfile.pyx":2795
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):
 *             pysam_set_bin(self._delegate, bin)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_bin); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_set_bin(__pyx_v_self->_delegate, __pyx_t_1);

  /* "pysam/calignmentfile.pyx":2794
 *         def __get__(self):
 *             return pysam_get_bin(self._delegate)
 *         def __set__(self, bin):             # <<<<<<<<<<<<<<
 *             pysam_set_bin(self._delegate, bin)
 * 
 */

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

/* "pysam/calignmentfile.pyx":2806
 *     property is_paired:
 *         """true if read is paired in sequencing"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_paired_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_paired_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9is_paired___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2807
 *         """true if read is paired in sequencing"""
 *         def __get__(self):
 *             return (self.flag & BAM_FPAIRED) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FPAIRED); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2806
 *     property is_paired:
 *         """true if read is paired in sequencing"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):
 */

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

/* "pysam/calignmentfile.pyx":2808
 *         def __get__(self):
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_paired_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9is_paired_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9is_paired_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2808);

  /* "pysam/calignmentfile.pyx":2809
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)             # <<<<<<<<<<<<<<
 * 
 *     property is_proper_pair:
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2809; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FPAIRED);

  /* "pysam/calignmentfile.pyx":2808
 *         def __get__(self):
 *             return (self.flag & BAM_FPAIRED) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPAIRED)
 * 
 */

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

/* "pysam/calignmentfile.pyx":2813
 *     property is_proper_pair:
 *         """true if read is mapped in a proper pair"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14is_proper_pair_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14is_proper_pair_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14is_proper_pair___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2814
 *         """true if read is mapped in a proper pair"""
 *         def __get__(self):
 *             return (self.flag & BAM_FPROPER_PAIR) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FPROPER_PAIR); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2813
 *     property is_proper_pair:
 *         """true if read is mapped in a proper pair"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):
 */

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

/* "pysam/calignmentfile.pyx":2815
 *         def __get__(self):
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)
 *     property is_unmapped:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14is_proper_pair_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14is_proper_pair_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14is_proper_pair_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2815);

  /* "pysam/calignmentfile.pyx":2816
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *     property is_unmapped:
 *         """true if read itself is unmapped"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2816; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FPROPER_PAIR);

  /* "pysam/calignmentfile.pyx":2815
 *         def __get__(self):
 *             return (self.flag & BAM_FPROPER_PAIR) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FPROPER_PAIR)
 *     property is_unmapped:
 */

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

/* "pysam/calignmentfile.pyx":2819
 *     property is_unmapped:
 *         """true if read itself is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11is_unmapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11is_unmapped___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2820
 *         """true if read itself is unmapped"""
 *         def __get__(self):
 *             return (self.flag & BAM_FUNMAP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2819
 *     property is_unmapped:
 *         """true if read itself is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):
 */

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

/* "pysam/calignmentfile.pyx":2821
 *         def __get__(self):
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)
 *     property mate_is_unmapped:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11is_unmapped_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11is_unmapped_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2821);

  /* "pysam/calignmentfile.pyx":2822
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)             # <<<<<<<<<<<<<<
 *     property mate_is_unmapped:
 *         """true if the mate is unmapped"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FUNMAP);

  /* "pysam/calignmentfile.pyx":2821
 *         def __get__(self):
 *             return (self.flag & BAM_FUNMAP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FUNMAP)
 *     property mate_is_unmapped:
 */

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

/* "pysam/calignmentfile.pyx":2825
 *     property mate_is_unmapped:
 *         """true if the mate is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16mate_is_unmapped_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16mate_is_unmapped___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2826
 *         """true if the mate is unmapped"""
 *         def __get__(self):
 *             return (self.flag & BAM_FMUNMAP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FMUNMAP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2825
 *     property mate_is_unmapped:
 *         """true if the mate is unmapped"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):
 */

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

/* "pysam/calignmentfile.pyx":2827
 *         def __get__(self):
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)
 *     property is_reverse:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16mate_is_unmapped_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16mate_is_unmapped_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16mate_is_unmapped_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2827);

  /* "pysam/calignmentfile.pyx":2828
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)             # <<<<<<<<<<<<<<
 *     property is_reverse:
 *         """true if read is mapped to reverse strand"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FMUNMAP);

  /* "pysam/calignmentfile.pyx":2827
 *         def __get__(self):
 *             return (self.flag & BAM_FMUNMAP) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMUNMAP)
 *     property is_reverse:
 */

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

/* "pysam/calignmentfile.pyx":2831
 *     property is_reverse:
 *         """true if read is mapped to reverse strand"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10is_reverse_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10is_reverse___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2832
 *         """true if read is mapped to reverse strand"""
 *         def __get__(self):
 *             return (self.flag & BAM_FREVERSE) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREVERSE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2831
 *     property is_reverse:
 *         """true if read is mapped to reverse strand"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):
 */

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

/* "pysam/calignmentfile.pyx":2833
 *         def __get__(self):
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)
 *     property mate_is_reverse:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10is_reverse_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_10is_reverse_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2833);

  /* "pysam/calignmentfile.pyx":2834
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)             # <<<<<<<<<<<<<<
 *     property mate_is_reverse:
 *         """true is read is mapped to reverse strand"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREVERSE);

  /* "pysam/calignmentfile.pyx":2833
 *         def __get__(self):
 *             return (self.flag & BAM_FREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREVERSE)
 *     property mate_is_reverse:
 */

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

/* "pysam/calignmentfile.pyx":2837
 *     property mate_is_reverse:
 *         """true is read is mapped to reverse strand"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mate_is_reverse_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mate_is_reverse_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15mate_is_reverse___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2838
 *         """true is read is mapped to reverse strand"""
 *         def __get__(self):
 *             return (self.flag & BAM_FMREVERSE) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FMREVERSE); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2837
 *     property mate_is_reverse:
 *         """true is read is mapped to reverse strand"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):
 */

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

/* "pysam/calignmentfile.pyx":2839
 *         def __get__(self):
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)
 *     property is_read1:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mate_is_reverse_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15mate_is_reverse_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15mate_is_reverse_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2839);

  /* "pysam/calignmentfile.pyx":2840
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)             # <<<<<<<<<<<<<<
 *     property is_read1:
 *         """true if this is read1"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FMREVERSE);

  /* "pysam/calignmentfile.pyx":2839
 *         def __get__(self):
 *             return (self.flag & BAM_FMREVERSE) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FMREVERSE)
 *     property is_read1:
 */

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

/* "pysam/calignmentfile.pyx":2843
 *     property is_read1:
 *         """true if this is read1"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read1_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read1_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8is_read1___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2844
 *         """true if this is read1"""
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD1) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREAD1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2843
 *     property is_read1:
 *         """true if this is read1"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):
 */

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

/* "pysam/calignmentfile.pyx":2845
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)
 *     property is_read2:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read1_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8is_read1_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8is_read1_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2845);

  /* "pysam/calignmentfile.pyx":2846
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)             # <<<<<<<<<<<<<<
 *     property is_read2:
 *         """true if this is read2"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREAD1);

  /* "pysam/calignmentfile.pyx":2845
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD1) != 0
 *         def __set__(self,val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD1)
 *     property is_read2:
 */

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

/* "pysam/calignmentfile.pyx":2849
 *     property is_read2:
 *         """true if this is read2"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read2_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read2_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8is_read2___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2850
 *         """true if this is read2"""
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD2) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FREAD2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2849
 *     property is_read2:
 *         """true if this is read2"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):
 */

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

/* "pysam/calignmentfile.pyx":2851
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)
 *     property is_secondary:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read2_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8is_read2_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_8is_read2_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2851);

  /* "pysam/calignmentfile.pyx":2852
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)             # <<<<<<<<<<<<<<
 *     property is_secondary:
 *         """true if not primary alignment"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FREAD2);

  /* "pysam/calignmentfile.pyx":2851
 *         def __get__(self):
 *             return (self.flag & BAM_FREAD2) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FREAD2)
 *     property is_secondary:
 */

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

/* "pysam/calignmentfile.pyx":2855
 *     property is_secondary:
 *         """true if not primary alignment"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_secondary_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_secondary_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12is_secondary___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2856
 *         """true if not primary alignment"""
 *         def __get__(self):
 *             return (self.flag & BAM_FSECONDARY) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FSECONDARY); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2855
 *     property is_secondary:
 *         """true if not primary alignment"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):
 */

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

/* "pysam/calignmentfile.pyx":2857
 *         def __get__(self):
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)
 *     property is_qcfail:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_secondary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12is_secondary_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12is_secondary_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2857);

  /* "pysam/calignmentfile.pyx":2858
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)             # <<<<<<<<<<<<<<
 *     property is_qcfail:
 *         """true if QC failure"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FSECONDARY);

  /* "pysam/calignmentfile.pyx":2857
 *         def __get__(self):
 *             return (self.flag & BAM_FSECONDARY) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FSECONDARY)
 *     property is_qcfail:
 */

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

/* "pysam/calignmentfile.pyx":2861
 *     property is_qcfail:
 *         """true if QC failure"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_qcfail_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_qcfail_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9is_qcfail___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2862
 *         """true if QC failure"""
 *         def __get__(self):
 *             return (self.flag & BAM_FQCFAIL) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FQCFAIL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2861
 *     property is_qcfail:
 *         """true if QC failure"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):
 */

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

/* "pysam/calignmentfile.pyx":2863
 *         def __get__(self):
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)
 *     property is_duplicate:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_qcfail_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9is_qcfail_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9is_qcfail_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2863);

  /* "pysam/calignmentfile.pyx":2864
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)             # <<<<<<<<<<<<<<
 *     property is_duplicate:
 *         """true if optical or PCR duplicate"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FQCFAIL);

  /* "pysam/calignmentfile.pyx":2863
 *         def __get__(self):
 *             return (self.flag & BAM_FQCFAIL) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FQCFAIL)
 *     property is_duplicate:
 */

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

/* "pysam/calignmentfile.pyx":2867
 *     property is_duplicate:
 *         """true if optical or PCR duplicate"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_duplicate_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_duplicate_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12is_duplicate___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2868
 *         """true if optical or PCR duplicate"""
 *         def __get__(self):
 *             return (self.flag & BAM_FDUP) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FDUP); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2867
 *     property is_duplicate:
 *         """true if optical or PCR duplicate"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):
 */

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

/* "pysam/calignmentfile.pyx":2869
 *         def __get__(self):
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)
 *     property is_supplementary:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_duplicate_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12is_duplicate_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12is_duplicate_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2869);

  /* "pysam/calignmentfile.pyx":2870
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)             # <<<<<<<<<<<<<<
 *     property is_supplementary:
 *         """true if this is a supplementary alignment"""
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FDUP);

  /* "pysam/calignmentfile.pyx":2869
 *         def __get__(self):
 *             return (self.flag & BAM_FDUP) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FDUP)
 *     property is_supplementary:
 */

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

/* "pysam/calignmentfile.pyx":2873
 *     property is_supplementary:
 *         """true if this is a supplementary alignment"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0
 *         def __set__(self, val):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16is_supplementary_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16is_supplementary_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16is_supplementary___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2874
 *         """true if this is a supplementary alignment"""
 *         def __get__(self):
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0             # <<<<<<<<<<<<<<
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(BAM_FSUPPLEMENTARY); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyNumber_And(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2873
 *     property is_supplementary:
 *         """true if this is a supplementary alignment"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0
 *         def __set__(self, val):
 */

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

/* "pysam/calignmentfile.pyx":2875
 *         def __get__(self):
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY)
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16is_supplementary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16is_supplementary_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16is_supplementary_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_val));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16is_supplementary_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_val) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint16_t __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 2875);

  /* "pysam/calignmentfile.pyx":2876
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0
 *         def __set__(self, val):
 *             pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY)             # <<<<<<<<<<<<<<
 * 
 *     # 2. Coordinates and lengths
 */
  __pyx_t_1 = __Pyx_PyInt_As_uint16_t(__pyx_v_val); if (unlikely((__pyx_t_1 == (uint16_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  pysam_update_flag(__pyx_v_self->_delegate, __pyx_t_1, BAM_FSUPPLEMENTARY);

  /* "pysam/calignmentfile.pyx":2875
 *         def __get__(self):
 *             return (self.flag & BAM_FSUPPLEMENTARY) != 0
 *         def __set__(self, val):             # <<<<<<<<<<<<<<
 *             pysam_update_flag(self._delegate, val, BAM_FSUPPLEMENTARY)
 * 
 */

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

/* "pysam/calignmentfile.pyx":2887
 * 
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_13reference_end_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_13reference_end_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_13reference_end___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_13reference_end___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  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_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2887);

  /* "pysam/calignmentfile.pyx":2889
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2890
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return bam_endpos(src)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_And(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_6 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  __pyx_t_2 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2891
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             return bam_endpos(src)
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2892
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 *             return bam_endpos(src)             # <<<<<<<<<<<<<<
 * 
 *     property reference_length:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_PyInt_From_int32_t(bam_endpos(__pyx_v_src)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2887
 * 
 *         '''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.reference_end.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2898
 * 
 *         This is equal to `aend - pos`. Returns None if not available.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16reference_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16reference_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16reference_length___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16reference_length___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  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_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2898);

  /* "pysam/calignmentfile.pyx":2900
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2901
 *             cdef bam1_t * src
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 *             return bam_endpos(src) - \
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_flag); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyInt_From_int(BAM_FUNMAP); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyNumber_And(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!__pyx_t_6) {
  } else {
    __pyx_t_2 = __pyx_t_6;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_6 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  __pyx_t_2 = __pyx_t_6;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2902
 *             src = self._delegate
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 *             return bam_endpos(src) - \
 *                 self._delegate.core.pos
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2903
 *             if (self.flag & BAM_FUNMAP) or pysam_get_n_cigar(src) == 0:
 *                 return None
 *             return bam_endpos(src) - \             # <<<<<<<<<<<<<<
 *                 self._delegate.core.pos
 * 
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/calignmentfile.pyx":2904
 *                 return None
 *             return bam_endpos(src) - \
 *                 self._delegate.core.pos             # <<<<<<<<<<<<<<
 * 
 *     property query_alignment_sequence:
 */
  __pyx_t_5 = __Pyx_PyInt_From_int((bam_endpos(__pyx_v_src) - __pyx_v_self->_delegate->core.pos)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2903; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2898
 * 
 *         This is equal to `aend - pos`. Returns None if not available.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.reference_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2923
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint32_t start, end
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_24query_alignment_sequence_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_24query_alignment_sequence_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_24query_alignment_sequence___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_24query_alignment_sequence___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int32_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2923);

  /* "pysam/calignmentfile.pyx":2927
 *             cdef uint32_t start, end
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0:
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2929
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  __pyx_t_2 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2930
 * 
 *             if src.core.l_qseq == 0:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             start = _getQueryStart(src)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2932
 *                 return None
 * 
 *             start = _getQueryStart(src)             # <<<<<<<<<<<<<<
 *             end   = _getQueryEnd(src)
 * 
 */
  __pyx_t_3 = __pyx_f_5pysam_14calignmentfile__getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2932; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_start = __pyx_t_3;

  /* "pysam/calignmentfile.pyx":2933
 * 
 *             start = _getQueryStart(src)
 *             end   = _getQueryEnd(src)             # <<<<<<<<<<<<<<
 * 
 *             return _getSequenceRange(src, start, end)
 */
  __pyx_t_3 = __pyx_f_5pysam_14calignmentfile__getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2933; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_end = __pyx_t_3;

  /* "pysam/calignmentfile.pyx":2935
 *             end   = _getQueryEnd(src)
 * 
 *             return _getSequenceRange(src, start, end)             # <<<<<<<<<<<<<<
 * 
 *     property query_alignment_qualities:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __pyx_f_5pysam_14calignmentfile__getSequenceRange(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2923
 *         """
 * 
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint32_t start, end
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.query_alignment_sequence.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2951
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint32_t start, end
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_25query_alignment_qualities_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_25query_alignment_qualities_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_25query_alignment_qualities___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_25query_alignment_qualities___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int32_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2951);

  /* "pysam/calignmentfile.pyx":2955
 *             cdef uint32_t start, end
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             if src.core.l_qseq == 0:
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2957
 *             src = self._delegate
 * 
 *             if src.core.l_qseq == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  __pyx_t_2 = ((__pyx_v_src->core.l_qseq == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":2958
 * 
 *             if src.core.l_qseq == 0:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             start = _getQueryStart(src)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":2960
 *                 return None
 * 
 *             start = _getQueryStart(src)             # <<<<<<<<<<<<<<
 *             end   = _getQueryEnd(src)
 * 
 */
  __pyx_t_3 = __pyx_f_5pysam_14calignmentfile__getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2960; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_start = __pyx_t_3;

  /* "pysam/calignmentfile.pyx":2961
 * 
 *             start = _getQueryStart(src)
 *             end   = _getQueryEnd(src)             # <<<<<<<<<<<<<<
 * 
 *             return _getQualitiesRange(src, start, end)
 */
  __pyx_t_3 = __pyx_f_5pysam_14calignmentfile__getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2961; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_end = __pyx_t_3;

  /* "pysam/calignmentfile.pyx":2963
 *             end   = _getQueryEnd(src)
 * 
 *             return _getQualitiesRange(src, start, end)             # <<<<<<<<<<<<<<
 * 
 *     property query_alignment_start:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __pyx_f_5pysam_14calignmentfile__getQualitiesRange(__pyx_v_src, __pyx_v_start, __pyx_v_end); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2951
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             cdef uint32_t start, end
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.query_alignment_qualities.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2973
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return _getQueryStart(self._delegate)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_21query_alignment_start_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_21query_alignment_start_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_21query_alignment_start___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2974
 *         """
 *         def __get__(self):
 *             return _getQueryStart(self._delegate)             # <<<<<<<<<<<<<<
 * 
 *     property query_alignment_end:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile__getQueryStart(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2974; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2974; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2973
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return _getQueryStart(self._delegate)
 * 
 */

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

/* "pysam/calignmentfile.pyx":2979
 *         """end index of the aligned query portion of the sequence (0-based,
 *         exclusive)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return _getQueryEnd(self._delegate)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_19query_alignment_end_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_19query_alignment_end_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_19query_alignment_end___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":2980
 *         exclusive)"""
 *         def __get__(self):
 *             return _getQueryEnd(self._delegate)             # <<<<<<<<<<<<<<
 * 
 *     property query_alignment_length:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile__getQueryEnd(__pyx_v_self->_delegate); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2980; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2979
 *         """end index of the aligned query portion of the sequence (0-based,
 *         exclusive)"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return _getQueryEnd(self._delegate)
 * 
 */

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

/* "pysam/calignmentfile.pyx":2986
 * 
 *         This is equal to :attr:`qend` - :attr:`qstart`"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_22query_alignment_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_22query_alignment_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_22query_alignment_length___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_22query_alignment_length___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int32_t __pyx_t_2;
  int32_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 2986);

  /* "pysam/calignmentfile.pyx":2988
 *         def __get__(self):
 *             cdef bam1_t * src
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             return _getQueryEnd(src) - _getQueryStart(src)
 * 
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":2989
 *             cdef bam1_t * src
 *             src = self._delegate
 *             return _getQueryEnd(src) - _getQueryStart(src)             # <<<<<<<<<<<<<<
 * 
 *     #####################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __pyx_f_5pysam_14calignmentfile__getQueryEnd(__pyx_v_src); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __pyx_f_5pysam_14calignmentfile__getQueryStart(__pyx_v_src); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_t_2 - __pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2989; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2986
 * 
 *         This is equal to :attr:`qend` - :attr:`qstart`"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef bam1_t * src
 *             src = self._delegate
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.query_alignment_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":2994
 *     # Computed properties
 * 
 *     def get_reference_positions(self, full_length=False):             # <<<<<<<<<<<<<<
 *         """a list of reference positions that this read aligns to.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_13get_reference_positions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_12get_reference_positions[] = "AlignedSegment.get_reference_positions(self, full_length=False)\na list of reference positions that this read aligns to.\n\n        By default, this method only returns positions in the\n        reference that are within the alignment. If *full_length* is\n        set, None values will be included for any soft-clipped or\n        unaligned positions within the read. The returned list will\n        thus be of the same length as the read.\n\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_13get_reference_positions(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_full_length = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_reference_positions (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_full_length,0};
    PyObject* values[1] = {0};
    values[0] = ((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  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_full_length);
          if (value) { values[0] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_reference_positions") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2994; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_full_length = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_reference_positions", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2994; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.get_reference_positions", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12get_reference_positions(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), __pyx_v_full_length);

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_12get_reference_positions(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_full_length) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_i;
  uint32_t __pyx_v_pos;
  int __pyx_v_op;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  int __pyx_v__full;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_l = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  bam1_t *__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int32_t __pyx_t_4;
  uint16_t __pyx_t_5;
  int __pyx_t_6;
  uint32_t __pyx_t_7;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("get_reference_positions", 0);
  __Pyx_TraceCall("get_reference_positions", __pyx_f[0], 2994);

  /* "pysam/calignmentfile.pyx":3008
 *         cdef uint32_t * cigar_p
 *         cdef bam1_t * src
 *         cdef bint _full = full_length             # <<<<<<<<<<<<<<
 * 
 *         src = self._delegate
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_full_length); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3008; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v__full = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":3010
 *         cdef bint _full = full_length
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         if pysam_get_n_cigar(src) == 0:
 *             return []
 */
  __pyx_t_2 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_2;

  /* "pysam/calignmentfile.pyx":3011
 * 
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return []
 * 
 */
  __pyx_t_1 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":3012
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:
 *             return []             # <<<<<<<<<<<<<<
 * 
 *         result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3012; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3014
 *             return []
 * 
 *         result = []             # <<<<<<<<<<<<<<
 *         pos = src.core.pos
 *         cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignmentfile.pyx":3015
 * 
 *         result = []
 *         pos = src.core.pos             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src)
 * 
 */
  __pyx_t_4 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_4;

  /* "pysam/calignmentfile.pyx":3016
 *         result = []
 *         pos = src.core.pos
 *         cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":3018
 *         cigar_p = pysam_bam_get_cigar(src)
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

    /* "pysam/calignmentfile.pyx":3019
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignmentfile.pyx":3020
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 * 
 *             if op == BAM_CSOFT_CLIP or op == BAM_CINS:
 */
    __pyx_t_3 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3020; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/calignmentfile.pyx":3022
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *             if op == BAM_CSOFT_CLIP or op == BAM_CINS:             # <<<<<<<<<<<<<<
 *                 if _full:
 *                     for i from 0 <= i < l:
 */
    __pyx_t_6 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
    if (!__pyx_t_6) {
    } else {
      __pyx_t_1 = __pyx_t_6;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_v_op == BAM_CINS) != 0);
    __pyx_t_1 = __pyx_t_6;
    __pyx_L7_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":3023
 * 
 *             if op == BAM_CSOFT_CLIP or op == BAM_CINS:
 *                 if _full:             # <<<<<<<<<<<<<<
 *                     for i from 0 <= i < l:
 *                         result.append(None)
 */
      __pyx_t_1 = (__pyx_v__full != 0);
      if (__pyx_t_1) {

        /* "pysam/calignmentfile.pyx":3024
 *             if op == BAM_CSOFT_CLIP or op == BAM_CINS:
 *                 if _full:
 *                     for i from 0 <= i < l:             # <<<<<<<<<<<<<<
 *                         result.append(None)
 *             elif op == BAM_CMATCH:
 */
        __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_l); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {

          /* "pysam/calignmentfile.pyx":3025
 *                 if _full:
 *                     for i from 0 <= i < l:
 *                         result.append(None)             # <<<<<<<<<<<<<<
 *             elif op == BAM_CMATCH:
 *                 for i from pos <= i < pos + l:
 */
          __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, Py_None); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        goto __pyx_L9;
      }
      __pyx_L9:;
      goto __pyx_L6;
    }

    /* "pysam/calignmentfile.pyx":3026
 *                     for i from 0 <= i < l:
 *                         result.append(None)
 *             elif op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                 for i from pos <= i < pos + l:
 *                     result.append(i)
 */
    __pyx_t_1 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":3027
 *                         result.append(None)
 *             elif op == BAM_CMATCH:
 *                 for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                     result.append(i)
 *                 pos += l
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_9); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3027; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_7; __pyx_v_i++) {

        /* "pysam/calignmentfile.pyx":3028
 *             elif op == BAM_CMATCH:
 *                 for i from pos <= i < pos + l:
 *                     result.append(i)             # <<<<<<<<<<<<<<
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
        __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }

      /* "pysam/calignmentfile.pyx":3029
 *                 for i from pos <= i < pos + l:
 *                     result.append(i)
 *                 pos += l             # <<<<<<<<<<<<<<
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 pos += l
 */
      __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_pos = __pyx_t_7;
      goto __pyx_L6;
    }

    /* "pysam/calignmentfile.pyx":3030
 *                     result.append(i)
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
    __pyx_t_6 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_6) {
    } else {
      __pyx_t_1 = __pyx_t_6;
      goto __pyx_L14_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
    __pyx_t_1 = __pyx_t_6;
    __pyx_L14_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":3031
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 pos += l             # <<<<<<<<<<<<<<
 * 
 *         return result
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_t_9); if (unlikely((__pyx_t_7 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_pos = __pyx_t_7;
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "pysam/calignmentfile.pyx":3033
 *                 pos += l
 * 
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def infer_query_length(self, always=True):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":2994
 *     # Computed properties
 * 
 *     def get_reference_positions(self, full_length=False):             # <<<<<<<<<<<<<<
 *         """a list of reference positions that this read aligns to.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.get_reference_positions", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3035
 *         return result
 * 
 *     def infer_query_length(self, always=True):             # <<<<<<<<<<<<<<
 *         """inferred read length from CIGAR string.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15infer_query_length(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_14infer_query_length[] = "AlignedSegment.infer_query_length(self, always=True)\ninferred read length from CIGAR string.\n\n        If *always* is set to True, the read length\n        will be always inferred. If set to False, the length\n        of the read sequence will be returned if it is\n        available.\n\n        Returns None if CIGAR string is not present.\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15infer_query_length(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_always = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("infer_query_length (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_always,0};
    PyObject* values[1] = {0};
    values[0] = ((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  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_always);
          if (value) { values[0] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "infer_query_length") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3035; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_always = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("infer_query_length", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3035; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.infer_query_length", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14infer_query_length(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), __pyx_v_always);

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_14infer_query_length(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_always) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_qpos;
  int __pyx_v_op;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  uint16_t __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("infer_query_length", 0);
  __Pyx_TraceCall("infer_query_length", __pyx_f[0], 3035);

  /* "pysam/calignmentfile.pyx":3050
 *         cdef bam1_t * src
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *         if not always and src.core.l_qseq:
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":3052
 *         src = self._delegate
 * 
 *         if not always and src.core.l_qseq:             # <<<<<<<<<<<<<<
 *             return src.core.l_qseq
 * 
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_always); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_src->core.l_qseq != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":3053
 * 
 *         if not always and src.core.l_qseq:
 *             return src.core.l_qseq             # <<<<<<<<<<<<<<
 * 
 *         if pysam_get_n_cigar(src) == 0:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_5 = __Pyx_PyInt_From_int32_t(__pyx_v_src->core.l_qseq); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3055
 *             return src.core.l_qseq
 * 
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return None
 * 
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":3056
 * 
 *         if pysam_get_n_cigar(src) == 0:
 *             return None             # <<<<<<<<<<<<<<
 * 
 *         qpos = 0
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3058
 *             return None
 * 
 *         qpos = 0             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src)
 * 
 */
  __pyx_v_qpos = 0;

  /* "pysam/calignmentfile.pyx":3059
 * 
 *         qpos = 0
 *         cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":3061
 *         cigar_p = pysam_bam_get_cigar(src)
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 * 
 */
  __pyx_t_6 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_6; __pyx_v_k++) {

    /* "pysam/calignmentfile.pyx":3062
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 * 
 *             if op == BAM_CMATCH or op == BAM_CINS or \
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignmentfile.pyx":3064
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 * 
 *             if op == BAM_CMATCH or op == BAM_CINS or \             # <<<<<<<<<<<<<<
 *                op == BAM_CSOFT_CLIP or \
 *                op == BAM_CEQUAL or op == BAM_CDIFF:
 */
    __pyx_t_4 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L10_bool_binop_done;
    }
    __pyx_t_4 = ((__pyx_v_op == BAM_CINS) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L10_bool_binop_done;
    }

    /* "pysam/calignmentfile.pyx":3065
 * 
 *             if op == BAM_CMATCH or op == BAM_CINS or \
 *                op == BAM_CSOFT_CLIP or \             # <<<<<<<<<<<<<<
 *                op == BAM_CEQUAL or op == BAM_CDIFF:
 *                 qpos += cigar_p[k] >> BAM_CIGAR_SHIFT
 */
    __pyx_t_4 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L10_bool_binop_done;
    }

    /* "pysam/calignmentfile.pyx":3066
 *             if op == BAM_CMATCH or op == BAM_CINS or \
 *                op == BAM_CSOFT_CLIP or \
 *                op == BAM_CEQUAL or op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *                 qpos += cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 */
    __pyx_t_4 = ((__pyx_v_op == BAM_CEQUAL) != 0);
    if (!__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L10_bool_binop_done;
    }
    __pyx_t_4 = ((__pyx_v_op == BAM_CDIFF) != 0);
    __pyx_t_2 = __pyx_t_4;
    __pyx_L10_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/calignmentfile.pyx":3067
 *                op == BAM_CSOFT_CLIP or \
 *                op == BAM_CEQUAL or op == BAM_CDIFF:
 *                 qpos += cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 * 
 *         return qpos
 */
      __pyx_v_qpos = (__pyx_v_qpos + ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT));
      goto __pyx_L9;
    }
    __pyx_L9:;
  }

  /* "pysam/calignmentfile.pyx":3069
 *                 qpos += cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *         return qpos             # <<<<<<<<<<<<<<
 * 
 *     def get_aligned_pairs(self, matches_only = False):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3069; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3035
 *         return result
 * 
 *     def infer_query_length(self, always=True):             # <<<<<<<<<<<<<<
 *         """inferred read length from CIGAR string.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.infer_query_length", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3071
 *         return qpos
 * 
 *     def get_aligned_pairs(self, matches_only = False):             # <<<<<<<<<<<<<<
 *         """a list of aligned read (query) and reference positions.
 *         For inserts, deletions, skipping either query or reference position may be None.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_17get_aligned_pairs(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_16get_aligned_pairs[] = "AlignedSegment.get_aligned_pairs(self, matches_only=False)\na list of aligned read (query) and reference positions.\n        For inserts, deletions, skipping either query or reference position may be None.\n\n        If @matches_only is True, only matched bases are returned - no None on either side.\n\n        Padding is currently not supported and leads to an exception\n        \n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_17get_aligned_pairs(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_matches_only = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_aligned_pairs (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_matches_only,0};
    PyObject* values[1] = {0};
    values[0] = ((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  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_matches_only);
          if (value) { values[0] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_aligned_pairs") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3071; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_matches_only = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_aligned_pairs", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3071; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.get_aligned_pairs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16get_aligned_pairs(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), __pyx_v_matches_only);

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_16get_aligned_pairs(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_matches_only) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_i;
  uint32_t __pyx_v_pos;
  uint32_t __pyx_v_qpos;
  int __pyx_v_op;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  int __pyx_v__matches_only;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_l = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  bam1_t *__pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int32_t __pyx_t_4;
  uint16_t __pyx_t_5;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  uint32_t __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("get_aligned_pairs", 0);
  __Pyx_TraceCall("get_aligned_pairs", __pyx_f[0], 3071);

  /* "pysam/calignmentfile.pyx":3086
 *         cdef int _matches_only
 * 
 *         _matches_only = bool(matches_only)             # <<<<<<<<<<<<<<
 * 
 *         src = self._delegate
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_matches_only); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v__matches_only = (!(!__pyx_t_1));

  /* "pysam/calignmentfile.pyx":3088
 *         _matches_only = bool(matches_only)
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         if pysam_get_n_cigar(src) == 0:
 *             return []
 */
  __pyx_t_2 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_2;

  /* "pysam/calignmentfile.pyx":3089
 * 
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return []
 * 
 */
  __pyx_t_1 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":3090
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:
 *             return []             # <<<<<<<<<<<<<<
 * 
 *         result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3090; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3092
 *             return []
 * 
 *         result = []             # <<<<<<<<<<<<<<
 *         pos = src.core.pos
 *         qpos = 0
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3092; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignmentfile.pyx":3093
 * 
 *         result = []
 *         pos = src.core.pos             # <<<<<<<<<<<<<<
 *         qpos = 0
 *         cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_t_4 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_4;

  /* "pysam/calignmentfile.pyx":3094
 *         result = []
 *         pos = src.core.pos
 *         qpos = 0             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src)
 * 
 */
  __pyx_v_qpos = 0;

  /* "pysam/calignmentfile.pyx":3095
 *         pos = src.core.pos
 *         qpos = 0
 *         cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":3097
 *         cigar_p = pysam_bam_get_cigar(src)
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

    /* "pysam/calignmentfile.pyx":3098
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignmentfile.pyx":3099
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 * 
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 */
    __pyx_t_3 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "pysam/calignmentfile.pyx":3101
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:             # <<<<<<<<<<<<<<
 *                 for i from pos <= i < pos + l:
 *                     result.append((qpos, i))
 */
    __pyx_t_6 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (!__pyx_t_6) {
    } else {
      __pyx_t_1 = __pyx_t_6;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_v_op == BAM_CEQUAL) != 0);
    if (!__pyx_t_6) {
    } else {
      __pyx_t_1 = __pyx_t_6;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_v_op == BAM_CDIFF) != 0);
    __pyx_t_1 = __pyx_t_6;
    __pyx_L7_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":3102
 * 
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 *                 for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                     result.append((qpos, i))
 *                     qpos += 1
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_7 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_8 = __Pyx_PyInt_As_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_8 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_8; __pyx_v_i++) {

        /* "pysam/calignmentfile.pyx":3103
 *             if op == BAM_CMATCH or op == BAM_CEQUAL or op == BAM_CDIFF:
 *                 for i from pos <= i < pos + l:
 *                     result.append((qpos, i))             # <<<<<<<<<<<<<<
 *                     qpos += 1
 *                 pos += l
 */
        __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_3);
        __pyx_t_7 = 0;
        __pyx_t_3 = 0;
        __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "pysam/calignmentfile.pyx":3104
 *                 for i from pos <= i < pos + l:
 *                     result.append((qpos, i))
 *                     qpos += 1             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
        __pyx_v_qpos = (__pyx_v_qpos + 1);
      }

      /* "pysam/calignmentfile.pyx":3105
 *                     result.append((qpos, i))
 *                     qpos += 1
 *                 pos += l             # <<<<<<<<<<<<<<
 * 
 *             elif op == BAM_CINS or op == BAM_CSOFT_CLIP:
 */
      __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_8 = __Pyx_PyInt_As_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_8 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_pos = __pyx_t_8;
      goto __pyx_L6;
    }

    /* "pysam/calignmentfile.pyx":3107
 *                 pos += l
 * 
 *             elif op == BAM_CINS or op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *                 if not _matches_only:
 *                     for i from pos <= i < pos + l:
 */
    __pyx_t_6 = ((__pyx_v_op == BAM_CINS) != 0);
    if (!__pyx_t_6) {
    } else {
      __pyx_t_1 = __pyx_t_6;
      goto __pyx_L12_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_v_op == BAM_CSOFT_CLIP) != 0);
    __pyx_t_1 = __pyx_t_6;
    __pyx_L12_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":3108
 * 
 *             elif op == BAM_CINS or op == BAM_CSOFT_CLIP:
 *                 if not _matches_only:             # <<<<<<<<<<<<<<
 *                     for i from pos <= i < pos + l:
 *                         result.append((qpos, None))
 */
      __pyx_t_1 = ((!(__pyx_v__matches_only != 0)) != 0);
      if (__pyx_t_1) {

        /* "pysam/calignmentfile.pyx":3109
 *             elif op == BAM_CINS or op == BAM_CSOFT_CLIP:
 *                 if not _matches_only:
 *                     for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                         result.append((qpos, None))
 *                         qpos += 1
 */
        __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = PyNumber_Add(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_8 = __Pyx_PyInt_As_uint32_t(__pyx_t_9); if (unlikely((__pyx_t_8 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3109; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_8; __pyx_v_i++) {

          /* "pysam/calignmentfile.pyx":3110
 *                 if not _matches_only:
 *                     for i from pos <= i < pos + l:
 *                         result.append((qpos, None))             # <<<<<<<<<<<<<<
 *                         qpos += 1
 *                 else:
 */
          __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_9);
          __Pyx_INCREF(Py_None);
          PyTuple_SET_ITEM(__pyx_t_3, 1, Py_None);
          __Pyx_GIVEREF(Py_None);
          __pyx_t_9 = 0;
          __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3110; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "pysam/calignmentfile.pyx":3111
 *                     for i from pos <= i < pos + l:
 *                         result.append((qpos, None))
 *                         qpos += 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     qpos += l
 */
          __pyx_v_qpos = (__pyx_v_qpos + 1);
        }
        goto __pyx_L14;
      }
      /*else*/ {

        /* "pysam/calignmentfile.pyx":3113
 *                         qpos += 1
 *                 else:
 *                     qpos += l             # <<<<<<<<<<<<<<
 * 
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
        __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_qpos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_v_l); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_8 = __Pyx_PyInt_As_uint32_t(__pyx_t_9); if (unlikely((__pyx_t_8 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_v_qpos = __pyx_t_8;
      }
      __pyx_L14:;
      goto __pyx_L6;
    }

    /* "pysam/calignmentfile.pyx":3115
 *                     qpos += l
 * 
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 if not _matches_only:
 *                     for i from pos <= i < pos + l:
 */
    __pyx_t_6 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_6) {
    } else {
      __pyx_t_1 = __pyx_t_6;
      goto __pyx_L17_bool_binop_done;
    }
    __pyx_t_6 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
    __pyx_t_1 = __pyx_t_6;
    __pyx_L17_bool_binop_done:;
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":3116
 * 
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 if not _matches_only:             # <<<<<<<<<<<<<<
 *                     for i from pos <= i < pos + l:
 *                         result.append((None, i))
 */
      __pyx_t_1 = ((!(__pyx_v__matches_only != 0)) != 0);
      if (__pyx_t_1) {

        /* "pysam/calignmentfile.pyx":3117
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 if not _matches_only:
 *                     for i from pos <= i < pos + l:             # <<<<<<<<<<<<<<
 *                         result.append((None, i))
 *                 pos += l
 */
        __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_3 = PyNumber_Add(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_8 = __Pyx_PyInt_As_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_8 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        for (__pyx_v_i = __pyx_v_pos; __pyx_v_i < __pyx_t_8; __pyx_v_i++) {

          /* "pysam/calignmentfile.pyx":3118
 *                 if not _matches_only:
 *                     for i from pos <= i < pos + l:
 *                         result.append((None, i))             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
          __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_i); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_INCREF(Py_None);
          PyTuple_SET_ITEM(__pyx_t_9, 0, Py_None);
          __Pyx_GIVEREF(Py_None);
          PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_9); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        goto __pyx_L19;
      }
      __pyx_L19:;

      /* "pysam/calignmentfile.pyx":3119
 *                     for i from pos <= i < pos + l:
 *                         result.append((None, i))
 *                 pos += l             # <<<<<<<<<<<<<<
 * 
 *             elif op == BAM_CHARD_CLIP:
 */
      __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_8 = __Pyx_PyInt_As_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_8 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_v_pos = __pyx_t_8;
      goto __pyx_L6;
    }

    /* "pysam/calignmentfile.pyx":3121
 *                 pos += l
 * 
 *             elif op == BAM_CHARD_CLIP:             # <<<<<<<<<<<<<<
 *                 pass # advances neither
 * 
 */
    __pyx_t_1 = ((__pyx_v_op == BAM_CHARD_CLIP) != 0);
    if (__pyx_t_1) {
      goto __pyx_L6;
    }

    /* "pysam/calignmentfile.pyx":3124
 *                 pass # advances neither
 * 
 *             elif op == BAM_CPAD:             # <<<<<<<<<<<<<<
 *                 raise NotImplementedError("Padding (BAM_CPAD, 6) is currently not supported. Please implement. Sorry about that.")
 * 
 */
    __pyx_t_1 = ((__pyx_v_op == BAM_CPAD) != 0);
    if (__pyx_t_1) {

      /* "pysam/calignmentfile.pyx":3125
 * 
 *             elif op == BAM_CPAD:
 *                 raise NotImplementedError("Padding (BAM_CPAD, 6) is currently not supported. Please implement. Sorry about that.")             # <<<<<<<<<<<<<<
 * 
 *         return result
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_NotImplementedError, __pyx_tuple__78, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L6:;
  }

  /* "pysam/calignmentfile.pyx":3127
 *                 raise NotImplementedError("Padding (BAM_CPAD, 6) is currently not supported. Please implement. Sorry about that.")
 * 
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def get_blocks(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3071
 *         return qpos
 * 
 *     def get_aligned_pairs(self, matches_only = False):             # <<<<<<<<<<<<<<
 *         """a list of aligned read (query) and reference positions.
 *         For inserts, deletions, skipping either query or reference position may be None.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.get_aligned_pairs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3129
 *         return result
 * 
 *     def get_blocks(self):             # <<<<<<<<<<<<<<
 *         """ a list of start and end positions of
 *         aligned gapless blocks.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_19get_blocks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_18get_blocks[] = "AlignedSegment.get_blocks(self)\n a list of start and end positions of\n        aligned gapless blocks.\n\n        The start and end positions are in genomic \n        coordinates. \n      \n        Blocks are not normalized, i.e. two blocks \n        might be directly adjacent. This happens if\n        the two blocks are separated by an insertion \n        in the read.\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_19get_blocks(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_blocks (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_18get_blocks(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_18get_blocks(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_pos;
  uint32_t __pyx_v_l;
  int __pyx_v_op;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int32_t __pyx_t_4;
  uint16_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("get_blocks", 0);
  __Pyx_TraceCall("get_blocks", __pyx_f[0], 3129);

  /* "pysam/calignmentfile.pyx":3147
 *         cdef bam1_t * src
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         if pysam_get_n_cigar(src) == 0:
 *             return []
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":3148
 * 
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return []
 * 
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":3149
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:
 *             return []             # <<<<<<<<<<<<<<
 * 
 *         result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3151
 *             return []
 * 
 *         result = []             # <<<<<<<<<<<<<<
 *         pos = src.core.pos
 *         cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignmentfile.pyx":3152
 * 
 *         result = []
 *         pos = src.core.pos             # <<<<<<<<<<<<<<
 *         cigar_p = pysam_bam_get_cigar(src)
 *         l = 0
 */
  __pyx_t_4 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_4;

  /* "pysam/calignmentfile.pyx":3153
 *         result = []
 *         pos = src.core.pos
 *         cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 *         l = 0
 * 
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":3154
 *         pos = src.core.pos
 *         cigar_p = pysam_bam_get_cigar(src)
 *         l = 0             # <<<<<<<<<<<<<<
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 */
  __pyx_v_l = 0;

  /* "pysam/calignmentfile.pyx":3156
 *         l = 0
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_5 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_5; __pyx_v_k++) {

    /* "pysam/calignmentfile.pyx":3157
 * 
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *             if op == BAM_CMATCH:
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignmentfile.pyx":3158
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *             if op == BAM_CMATCH:
 *                 result.append((pos, pos + l))
 */
    __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT);

    /* "pysam/calignmentfile.pyx":3159
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *             if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                 result.append((pos, pos + l))
 *                 pos += l
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (__pyx_t_2) {

      /* "pysam/calignmentfile.pyx":3160
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *             if op == BAM_CMATCH:
 *                 result.append((pos, pos + l))             # <<<<<<<<<<<<<<
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
      __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyInt_From_uint32_t((__pyx_v_pos + __pyx_v_l)); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_6);
      __pyx_t_3 = 0;
      __pyx_t_6 = 0;
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_8 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pysam/calignmentfile.pyx":3161
 *             if op == BAM_CMATCH:
 *                 result.append((pos, pos + l))
 *                 pos += l             # <<<<<<<<<<<<<<
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 pos += l
 */
      __pyx_v_pos = (__pyx_v_pos + __pyx_v_l);
      goto __pyx_L6;
    }

    /* "pysam/calignmentfile.pyx":3162
 *                 result.append((pos, pos + l))
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
    __pyx_t_9 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_9) {
    } else {
      __pyx_t_2 = __pyx_t_9;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_9 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
    __pyx_t_2 = __pyx_t_9;
    __pyx_L7_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/calignmentfile.pyx":3163
 *                 pos += l
 *             elif op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 pos += l             # <<<<<<<<<<<<<<
 * 
 *         return result
 */
      __pyx_v_pos = (__pyx_v_pos + __pyx_v_l);
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "pysam/calignmentfile.pyx":3165
 *                 pos += l
 * 
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def get_overlap(self, uint32_t start, uint32_t end):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3129
 *         return result
 * 
 *     def get_blocks(self):             # <<<<<<<<<<<<<<
 *         """ a list of start and end positions of
 *         aligned gapless blocks.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.get_blocks", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3167
 *         return result
 * 
 *     def get_overlap(self, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
 *         """return number of aligned bases of read overlapping the interval
 *         *start* and *end* on the reference sequence.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_21get_overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_20get_overlap[] = "AlignedSegment.get_overlap(self, uint32_t start, uint32_t end)\nreturn number of aligned bases of read overlapping the interval\n        *start* and *end* on the reference sequence.\n\n        Return None if cigar alignment is not available.\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_21get_overlap(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  uint32_t __pyx_v_start;
  uint32_t __pyx_v_end;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_overlap (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_start,&__pyx_n_s_end,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("get_overlap", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3167; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_overlap") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3167; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_start = __Pyx_PyInt_As_uint32_t(values[0]); if (unlikely((__pyx_v_start == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3167; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    __pyx_v_end = __Pyx_PyInt_As_uint32_t(values[1]); if (unlikely((__pyx_v_end == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3167; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_overlap", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3167; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.get_overlap", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_20get_overlap(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), __pyx_v_start, __pyx_v_end);

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_20get_overlap(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, uint32_t __pyx_v_start, uint32_t __pyx_v_end) {
  uint32_t __pyx_v_k;
  uint32_t __pyx_v_pos;
  uint32_t __pyx_v_overlap;
  int __pyx_v_op;
  int __pyx_v_o;
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_l = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int32_t __pyx_t_3;
  uint16_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  uint32_t __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  uint32_t __pyx_t_10;
  uint32_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("get_overlap", 0);
  __Pyx_TraceCall("get_overlap", __pyx_f[0], 3167);

  /* "pysam/calignmentfile.pyx":3178
 *         cdef bam1_t * src
 * 
 *         overlap = 0             # <<<<<<<<<<<<<<
 * 
 *         src = self._delegate
 */
  __pyx_v_overlap = 0;

  /* "pysam/calignmentfile.pyx":3180
 *         overlap = 0
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         if pysam_get_n_cigar(src) == 0:
 *             return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":3181
 * 
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *             return None
 *         pos = src.core.pos
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":3182
 *         src = self._delegate
 *         if pysam_get_n_cigar(src) == 0:
 *             return None             # <<<<<<<<<<<<<<
 *         pos = src.core.pos
 *         o = 0
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3183
 *         if pysam_get_n_cigar(src) == 0:
 *             return None
 *         pos = src.core.pos             # <<<<<<<<<<<<<<
 *         o = 0
 * 
 */
  __pyx_t_3 = __pyx_v_src->core.pos;
  __pyx_v_pos = __pyx_t_3;

  /* "pysam/calignmentfile.pyx":3184
 *             return None
 *         pos = src.core.pos
 *         o = 0             # <<<<<<<<<<<<<<
 * 
 *         cigar_p = pysam_bam_get_cigar(src)
 */
  __pyx_v_o = 0;

  /* "pysam/calignmentfile.pyx":3186
 *         o = 0
 * 
 *         cigar_p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":3187
 * 
 *         cigar_p = pysam_bam_get_cigar(src)
 *         for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_4 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {

    /* "pysam/calignmentfile.pyx":3188
 *         cigar_p = pysam_bam_get_cigar(src)
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignmentfile.pyx":3189
 *         for k from 0 <= k < pysam_get_n_cigar(src):
 *             op = cigar_p[k] & BAM_CIGAR_MASK
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 * 
 *             if op == BAM_CMATCH:
 */
    __pyx_t_5 = __Pyx_PyInt_From_uint32_t(((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "pysam/calignmentfile.pyx":3191
 *             l = cigar_p[k] >> BAM_CIGAR_SHIFT
 * 
 *             if op == BAM_CMATCH:             # <<<<<<<<<<<<<<
 *                 o = min( pos + l, end) - max( pos, start )
 *                 if o > 0: overlap += o
 */
    __pyx_t_2 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (__pyx_t_2) {

      /* "pysam/calignmentfile.pyx":3192
 * 
 *             if op == BAM_CMATCH:
 *                 o = min( pos + l, end) - max( pos, start )             # <<<<<<<<<<<<<<
 *                 if o > 0: overlap += o
 * 
 */
      __pyx_t_6 = __pyx_v_end;
      __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = PyNumber_Add(__pyx_t_5, __pyx_v_l); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = PyObject_RichCompare(__pyx_t_8, __pyx_t_7, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_2) {
        __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_5 = __pyx_t_9;
        __pyx_t_9 = 0;
      } else {
        __Pyx_INCREF(__pyx_t_7);
        __pyx_t_5 = __pyx_t_7;
      }
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_6 = __pyx_v_start;
      __pyx_t_10 = __pyx_v_pos;
      if (((__pyx_t_6 > __pyx_t_10) != 0)) {
        __pyx_t_11 = __pyx_t_6;
      } else {
        __pyx_t_11 = __pyx_t_10;
      }
      __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_t_11); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_9 = PyNumber_Subtract(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_9); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_o = __pyx_t_12;

      /* "pysam/calignmentfile.pyx":3193
 *             if op == BAM_CMATCH:
 *                 o = min( pos + l, end) - max( pos, start )
 *                 if o > 0: overlap += o             # <<<<<<<<<<<<<<
 * 
 *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
 */
      __pyx_t_2 = ((__pyx_v_o > 0) != 0);
      if (__pyx_t_2) {
        __pyx_v_overlap = (__pyx_v_overlap + __pyx_v_o);
        goto __pyx_L7;
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysam/calignmentfile.pyx":3195
 *                 if o > 0: overlap += o
 * 
 *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:             # <<<<<<<<<<<<<<
 *                 pos += l
 * 
 */
    __pyx_t_13 = ((__pyx_v_op == BAM_CMATCH) != 0);
    if (!__pyx_t_13) {
    } else {
      __pyx_t_2 = __pyx_t_13;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_13 = ((__pyx_v_op == BAM_CDEL) != 0);
    if (!__pyx_t_13) {
    } else {
      __pyx_t_2 = __pyx_t_13;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_t_13 = ((__pyx_v_op == BAM_CREF_SKIP) != 0);
    __pyx_t_2 = __pyx_t_13;
    __pyx_L9_bool_binop_done:;
    if (__pyx_t_2) {

      /* "pysam/calignmentfile.pyx":3196
 * 
 *             if op == BAM_CMATCH or op == BAM_CDEL or op == BAM_CREF_SKIP:
 *                 pos += l             # <<<<<<<<<<<<<<
 * 
 *         return overlap
 */
      __pyx_t_9 = __Pyx_PyInt_From_uint32_t(__pyx_v_pos); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_t_9, __pyx_v_l); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_11 = __Pyx_PyInt_As_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_11 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_v_pos = __pyx_t_11;
      goto __pyx_L8;
    }
    __pyx_L8:;
  }

  /* "pysam/calignmentfile.pyx":3198
 *                 pos += l
 * 
 *         return overlap             # <<<<<<<<<<<<<<
 * 
 *     #####################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_overlap); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3167
 *         return result
 * 
 *     def get_overlap(self, uint32_t start, uint32_t end):             # <<<<<<<<<<<<<<
 *         """return number of aligned bases of read overlapping the interval
 *         *start* and *end* on the reference sequence.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.get_overlap", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3241
 *         or None.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * cigar_p
 *             cdef bam1_t * src
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigartuples_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigartuples_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigartuples___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigartuples___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  uint32_t *__pyx_v_cigar_p;
  bam1_t *__pyx_v_src;
  uint32_t __pyx_v_op;
  uint32_t __pyx_v_l;
  int __pyx_v_k;
  PyObject *__pyx_v_cigar = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  uint16_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3241);

  /* "pysam/calignmentfile.pyx":3247
 *             cdef int k
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 *             if pysam_get_n_cigar(src) == 0:
 *                 return None
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":3248
 * 
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:             # <<<<<<<<<<<<<<
 *                 return None
 * 
 */
  __pyx_t_2 = ((pysam_get_n_cigar(__pyx_v_src) == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":3249
 *             src = self._delegate
 *             if pysam_get_n_cigar(src) == 0:
 *                 return None             # <<<<<<<<<<<<<<
 * 
 *             cigar = []
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3251
 *                 return None
 * 
 *             cigar = []             # <<<<<<<<<<<<<<
 * 
 *             cigar_p = pysam_bam_get_cigar(src);
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_cigar = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignmentfile.pyx":3253
 *             cigar = []
 * 
 *             cigar_p = pysam_bam_get_cigar(src);             # <<<<<<<<<<<<<<
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_v_cigar_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":3254
 * 
 *             cigar_p = pysam_bam_get_cigar(src);
 *             for k from 0 <= k < pysam_get_n_cigar(src):             # <<<<<<<<<<<<<<
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 */
  __pyx_t_4 = pysam_get_n_cigar(__pyx_v_src);
  for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_4; __pyx_v_k++) {

    /* "pysam/calignmentfile.pyx":3255
 *             cigar_p = pysam_bam_get_cigar(src);
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & BAM_CIGAR_MASK);

    /* "pysam/calignmentfile.pyx":3256
 *             for k from 0 <= k < pysam_get_n_cigar(src):
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT             # <<<<<<<<<<<<<<
 *                 cigar.append((op, l))
 *             return cigar
 */
    __pyx_v_l = ((__pyx_v_cigar_p[__pyx_v_k]) >> BAM_CIGAR_SHIFT);

    /* "pysam/calignmentfile.pyx":3257
 *                 op = cigar_p[k] & BAM_CIGAR_MASK
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))             # <<<<<<<<<<<<<<
 *             return cigar
 * 
 */
    __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_op); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyInt_From_uint32_t(__pyx_v_l); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_3 = 0;
    __pyx_t_5 = 0;
    __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_cigar, __pyx_t_6); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }

  /* "pysam/calignmentfile.pyx":3258
 *                 l = cigar_p[k] >> BAM_CIGAR_SHIFT
 *                 cigar.append((op, l))
 *             return cigar             # <<<<<<<<<<<<<<
 * 
 *         def __set__(self, values):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_cigar);
  __pyx_r = __pyx_v_cigar;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3241
 *         or None.
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * cigar_p
 *             cdef bam1_t * src
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.cigartuples.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_cigar);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3260
 *             return cigar
 * 
 *         def __set__(self, values):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * p
 *             cdef bam1_t * src
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigartuples_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigartuples_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_values) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigartuples_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_values));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_11cigartuples_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_values) {
  uint32_t *__pyx_v_p;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_v_op = 0;
  PyObject *__pyx_v_l = 0;
  int __pyx_v_k;
  int __pyx_v_ncigar;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *(*__pyx_t_11)(PyObject *);
  uint32_t __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3260);
  __Pyx_INCREF(__pyx_v_values);

  /* "pysam/calignmentfile.pyx":3266
 *             cdef int k, ncigar
 * 
 *             k = 0             # <<<<<<<<<<<<<<
 * 
 *             src = self._delegate
 */
  __pyx_v_k = 0;

  /* "pysam/calignmentfile.pyx":3268
 *             k = 0
 * 
 *             src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *             # get location of cigar string
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":3271
 * 
 *             # get location of cigar string
 *             p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *             # empty values for cigar string
 */
  __pyx_v_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":3274
 * 
 *             # empty values for cigar string
 *             if values is None:             # <<<<<<<<<<<<<<
 *                 values = []
 * 
 */
  __pyx_t_2 = (__pyx_v_values == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysam/calignmentfile.pyx":3275
 *             # empty values for cigar string
 *             if values is None:
 *                 values = []             # <<<<<<<<<<<<<<
 * 
 *             ncigar = len(values)
 */
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF_SET(__pyx_v_values, __pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":3277
 *                 values = []
 * 
 *             ncigar = len(values)             # <<<<<<<<<<<<<<
 *             # create space for cigar data within src.data
 *             pysam_bam_update(src,
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_values); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3277; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_ncigar = __pyx_t_5;

  /* "pysam/calignmentfile.pyx":3279
 *             ncigar = len(values)
 *             # create space for cigar data within src.data
 *             pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                              pysam_get_n_cigar(src) * 4,
 *                              ncigar * 4,
 */
  pysam_bam_update(__pyx_v_src, (pysam_get_n_cigar(__pyx_v_src) * 4), (__pyx_v_ncigar * 4), ((uint8_t *)__pyx_v_p));

  /* "pysam/calignmentfile.pyx":3285
 * 
 *             # length is number of cigar operations, not bytes
 *             pysam_set_n_cigar(src, ncigar)             # <<<<<<<<<<<<<<
 * 
 *             # re-acquire pointer to location in memory
 */
  pysam_set_n_cigar(__pyx_v_src, __pyx_v_ncigar);

  /* "pysam/calignmentfile.pyx":3289
 *             # re-acquire pointer to location in memory
 *             # as it might have moved
 *             p = pysam_bam_get_cigar(src)             # <<<<<<<<<<<<<<
 * 
 *             # insert cigar operations
 */
  __pyx_v_p = pysam_bam_get_cigar(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":3292
 * 
 *             # insert cigar operations
 *             for op, l in values:             # <<<<<<<<<<<<<<
 *                 p[k] = l << BAM_CIGAR_SHIFT | op
 *                 k += 1
 */
  if (likely(PyList_CheckExact(__pyx_v_values)) || PyTuple_CheckExact(__pyx_v_values)) {
    __pyx_t_4 = __pyx_v_values; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_values); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_4);
      if (unlikely(!__pyx_t_7)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
      PyObject* sequence = __pyx_t_7;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_8 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_9 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_9);
      #else
      __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      #endif
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_10 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
      index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_8);
      index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_9)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_9);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_11 = NULL;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L7_unpacking_done;
      __pyx_L6_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_11 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3292; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L7_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_op, __pyx_t_8);
    __pyx_t_8 = 0;
    __Pyx_XDECREF_SET(__pyx_v_l, __pyx_t_9);
    __pyx_t_9 = 0;

    /* "pysam/calignmentfile.pyx":3293
 *             # insert cigar operations
 *             for op, l in values:
 *                 p[k] = l << BAM_CIGAR_SHIFT | op             # <<<<<<<<<<<<<<
 *                 k += 1
 * 
 */
    __pyx_t_7 = __Pyx_PyInt_From_int(BAM_CIGAR_SHIFT); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = PyNumber_Lshift(__pyx_v_l, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_Or(__pyx_t_9, __pyx_v_op); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_12 = __Pyx_PyInt_As_uint32_t(__pyx_t_7); if (unlikely((__pyx_t_12 == (uint32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    (__pyx_v_p[__pyx_v_k]) = __pyx_t_12;

    /* "pysam/calignmentfile.pyx":3294
 *             for op, l in values:
 *                 p[k] = l << BAM_CIGAR_SHIFT | op
 *                 k += 1             # <<<<<<<<<<<<<<
 * 
 *             ## setting the cigar string requires updating the bin
 */
    __pyx_v_k = (__pyx_v_k + 1);

    /* "pysam/calignmentfile.pyx":3292
 * 
 *             # insert cigar operations
 *             for op, l in values:             # <<<<<<<<<<<<<<
 *                 p[k] = l << BAM_CIGAR_SHIFT | op
 *                 k += 1
 */
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":3297
 * 
 *             ## setting the cigar string requires updating the bin
 *             pysam_set_bin(src,             # <<<<<<<<<<<<<<
 *                           hts_reg2bin(
 *                               src.core.pos,
 */
  pysam_set_bin(__pyx_v_src, hts_reg2bin(__pyx_v_src->core.pos, bam_endpos(__pyx_v_src), 14, 5));

  /* "pysam/calignmentfile.pyx":3260
 *             return cigar
 * 
 *         def __set__(self, values):             # <<<<<<<<<<<<<<
 *             cdef uint32_t * p
 *             cdef bam1_t * src
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.cigartuples.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_op);
  __Pyx_XDECREF(__pyx_v_l);
  __Pyx_XDECREF(__pyx_v_values);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3305
 * 
 * 
 *     cpdef set_tag(self,             # <<<<<<<<<<<<<<
 *                   tag,
 *                   value,
 */

static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_23set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_14AlignedSegment_set_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_14calignmentfile_14AlignedSegment_set_tag *__pyx_optional_args) {

  /* "pysam/calignmentfile.pyx":3308
 *                   tag,
 *                   value,
 *                   value_type=None,             # <<<<<<<<<<<<<<
 *                   replace=True):
 *         """sets a particular field *tag* to *value* in the optional alignment
 */
  PyObject *__pyx_v_value_type = ((PyObject *)Py_None);

  /* "pysam/calignmentfile.pyx":3309
 *                   value,
 *                   value_type=None,
 *                   replace=True):             # <<<<<<<<<<<<<<
 *         """sets a particular field *tag* to *value* in the optional alignment
 *         section.
 */
  PyObject *__pyx_v_replace = ((PyObject *)Py_True);
  int __pyx_v_value_size;
  uint8_t *__pyx_v_value_ptr;
  uint8_t *__pyx_v_existing_ptr;
  uint8_t __pyx_v_type_code;
  float __pyx_v_float_value;
  double __pyx_v_double_value;
  int32_t __pyx_v_int_value;
  bam1_t *__pyx_v_src;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  bam1_t *__pyx_t_7;
  int __pyx_t_8;
  char const *__pyx_t_9;
  int __pyx_t_10;
  uint8_t __pyx_t_11;
  struct __pyx_opt_args_5pysam_14calignmentfile__get_value_code __pyx_t_12;
  char *__pyx_t_13;
  int32_t __pyx_t_14;
  double __pyx_t_15;
  float __pyx_t_16;
  char const *__pyx_t_17;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("set_tag", 0);
  __Pyx_TraceCall("set_tag", __pyx_f[0], 3305);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_value_type = __pyx_optional_args->value_type;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_replace = __pyx_optional_args->replace;
      }
    }
  }
  __Pyx_INCREF(__pyx_v_tag);
  __Pyx_INCREF(__pyx_v_value);

  /* "pysam/calignmentfile.pyx":3305
 * 
 * 
 *     cpdef set_tag(self,             # <<<<<<<<<<<<<<
 *                   tag,
 *                   value,
 */
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_23set_tag)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      __pyx_t_5 = 0;
      if (CYTHON_COMPILING_IN_CPYTHON && 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_5 = 1;
        }
      }
      __pyx_t_6 = PyTuple_New(4+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      if (__pyx_t_4) {
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(__pyx_v_tag);
      PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_tag);
      __Pyx_GIVEREF(__pyx_v_tag);
      __Pyx_INCREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      __Pyx_INCREF(__pyx_v_value_type);
      PyTuple_SET_ITEM(__pyx_t_6, 2+__pyx_t_5, __pyx_v_value_type);
      __Pyx_GIVEREF(__pyx_v_value_type);
      __Pyx_INCREF(__pyx_v_replace);
      PyTuple_SET_ITEM(__pyx_t_6, 3+__pyx_t_5, __pyx_v_replace);
      __Pyx_GIVEREF(__pyx_v_replace);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/calignmentfile.pyx":3332
 *         cdef double   double_value
 *         cdef int32_t  int_value
 *         cdef bam1_t * src = self._delegate             # <<<<<<<<<<<<<<
 *         cdef char * _value_type
 * 
 */
  __pyx_t_7 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_7;

  /* "pysam/calignmentfile.pyx":3335
 *         cdef char * _value_type
 * 
 *         if len(tag) != 2:             # <<<<<<<<<<<<<<
 *             raise ValueError('Invalid tag: %s' % tag)
 * 
 */
  __pyx_t_5 = PyObject_Length(__pyx_v_tag); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3335; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_8 = ((__pyx_t_5 != 2) != 0);
  if (__pyx_t_8) {

    /* "pysam/calignmentfile.pyx":3336
 * 
 *         if len(tag) != 2:
 *             raise ValueError('Invalid tag: %s' % tag)             # <<<<<<<<<<<<<<
 * 
 *         tag = _forceBytes(tag)
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_tag_s, __pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":3338
 *             raise ValueError('Invalid tag: %s' % tag)
 * 
 *         tag = _forceBytes(tag)             # <<<<<<<<<<<<<<
 *         if replace:
 *             existing_ptr = bam_aux_get(src, tag)
 */
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile__forceBytes(__pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3338; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF_SET(__pyx_v_tag, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":3339
 * 
 *         tag = _forceBytes(tag)
 *         if replace:             # <<<<<<<<<<<<<<
 *             existing_ptr = bam_aux_get(src, tag)
 *             if existing_ptr:
 */
  __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_replace); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_8) {

    /* "pysam/calignmentfile.pyx":3340
 *         tag = _forceBytes(tag)
 *         if replace:
 *             existing_ptr = bam_aux_get(src, tag)             # <<<<<<<<<<<<<<
 *             if existing_ptr:
 *                 bam_aux_del(src, existing_ptr)
 */
    __pyx_t_9 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_9) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3340; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_existing_ptr = bam_aux_get(__pyx_v_src, __pyx_t_9);

    /* "pysam/calignmentfile.pyx":3341
 *         if replace:
 *             existing_ptr = bam_aux_get(src, tag)
 *             if existing_ptr:             # <<<<<<<<<<<<<<
 *                 bam_aux_del(src, existing_ptr)
 * 
 */
    __pyx_t_8 = (__pyx_v_existing_ptr != 0);
    if (__pyx_t_8) {

      /* "pysam/calignmentfile.pyx":3342
 *             existing_ptr = bam_aux_get(src, tag)
 *             if existing_ptr:
 *                 bam_aux_del(src, existing_ptr)             # <<<<<<<<<<<<<<
 * 
 *         # setting value to None deletes a tag
 */
      bam_aux_del(__pyx_v_src, __pyx_v_existing_ptr);
      goto __pyx_L5;
    }
    __pyx_L5:;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "pysam/calignmentfile.pyx":3345
 * 
 *         # setting value to None deletes a tag
 *         if value is None:             # <<<<<<<<<<<<<<
 *             return
 * 
 */
  __pyx_t_8 = (__pyx_v_value == Py_None);
  __pyx_t_10 = (__pyx_t_8 != 0);
  if (__pyx_t_10) {

    /* "pysam/calignmentfile.pyx":3346
 *         # setting value to None deletes a tag
 *         if value is None:
 *             return             # <<<<<<<<<<<<<<
 * 
 *         type_code = _get_value_code(value, value_type)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3348
 *             return
 * 
 *         type_code = _get_value_code(value, value_type)             # <<<<<<<<<<<<<<
 *         if type_code == 0:
 *             raise ValueError("can't guess type or invalid type code specified")
 */
  __pyx_t_12.__pyx_n = 1;
  __pyx_t_12.value_type = __pyx_v_value_type;
  __pyx_t_11 = __pyx_f_5pysam_14calignmentfile__get_value_code(__pyx_v_value, &__pyx_t_12); 
  __pyx_v_type_code = __pyx_t_11;

  /* "pysam/calignmentfile.pyx":3349
 * 
 *         type_code = _get_value_code(value, value_type)
 *         if type_code == 0:             # <<<<<<<<<<<<<<
 *             raise ValueError("can't guess type or invalid type code specified")
 * 
 */
  __pyx_t_10 = ((__pyx_v_type_code == 0) != 0);
  if (__pyx_t_10) {

    /* "pysam/calignmentfile.pyx":3350
 *         type_code = _get_value_code(value, value_type)
 *         if type_code == 0:
 *             raise ValueError("can't guess type or invalid type code specified")             # <<<<<<<<<<<<<<
 * 
 *         # Not Endian-safe, but then again neither is samtools!
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__79, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":3365
 *             value_ptr    = <uint8_t*>&double_value
 *             value_size   = sizeof(double)
 *         elif type_code == 'f':             # <<<<<<<<<<<<<<
 *             float_value  = value
 *             value_ptr    = <uint8_t*>&float_value
 */
  switch (__pyx_v_type_code) {

    /* "pysam/calignmentfile.pyx":3353
 * 
 *         # Not Endian-safe, but then again neither is samtools!
 *         if type_code == 'Z':             # <<<<<<<<<<<<<<
 *             value = _forceBytes(value)
 *             value_ptr    = <uint8_t*><char*>value
 */
    case 'Z':

    /* "pysam/calignmentfile.pyx":3354
 *         # Not Endian-safe, but then again neither is samtools!
 *         if type_code == 'Z':
 *             value = _forceBytes(value)             # <<<<<<<<<<<<<<
 *             value_ptr    = <uint8_t*><char*>value
 *             value_size   = len(value)+1
 */
    __pyx_t_1 = __pyx_f_5pysam_14calignmentfile__forceBytes(__pyx_v_value); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_value, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "pysam/calignmentfile.pyx":3355
 *         if type_code == 'Z':
 *             value = _forceBytes(value)
 *             value_ptr    = <uint8_t*><char*>value             # <<<<<<<<<<<<<<
 *             value_size   = len(value)+1
 *         elif type_code == 'i':
 */
    __pyx_t_13 = __Pyx_PyObject_AsString(__pyx_v_value); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_value_ptr = ((uint8_t *)((char *)__pyx_t_13));

    /* "pysam/calignmentfile.pyx":3356
 *             value = _forceBytes(value)
 *             value_ptr    = <uint8_t*><char*>value
 *             value_size   = len(value)+1             # <<<<<<<<<<<<<<
 *         elif type_code == 'i':
 *             int_value    = value
 */
    __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_value_size = (__pyx_t_5 + 1);
    break;

    /* "pysam/calignmentfile.pyx":3357
 *             value_ptr    = <uint8_t*><char*>value
 *             value_size   = len(value)+1
 *         elif type_code == 'i':             # <<<<<<<<<<<<<<
 *             int_value    = value
 *             value_ptr    = <uint8_t*>&int_value
 */
    case 'i':

    /* "pysam/calignmentfile.pyx":3358
 *             value_size   = len(value)+1
 *         elif type_code == 'i':
 *             int_value    = value             # <<<<<<<<<<<<<<
 *             value_ptr    = <uint8_t*>&int_value
 *             value_size   = sizeof(int32_t)
 */
    __pyx_t_14 = __Pyx_PyInt_As_int32_t(__pyx_v_value); if (unlikely((__pyx_t_14 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3358; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_int_value = __pyx_t_14;

    /* "pysam/calignmentfile.pyx":3359
 *         elif type_code == 'i':
 *             int_value    = value
 *             value_ptr    = <uint8_t*>&int_value             # <<<<<<<<<<<<<<
 *             value_size   = sizeof(int32_t)
 *         elif type_code == 'd':
 */
    __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_int_value));

    /* "pysam/calignmentfile.pyx":3360
 *             int_value    = value
 *             value_ptr    = <uint8_t*>&int_value
 *             value_size   = sizeof(int32_t)             # <<<<<<<<<<<<<<
 *         elif type_code == 'd':
 *             double_value = value
 */
    __pyx_v_value_size = (sizeof(int32_t));
    break;

    /* "pysam/calignmentfile.pyx":3361
 *             value_ptr    = <uint8_t*>&int_value
 *             value_size   = sizeof(int32_t)
 *         elif type_code == 'd':             # <<<<<<<<<<<<<<
 *             double_value = value
 *             value_ptr    = <uint8_t*>&double_value
 */
    case 'd':

    /* "pysam/calignmentfile.pyx":3362
 *             value_size   = sizeof(int32_t)
 *         elif type_code == 'd':
 *             double_value = value             # <<<<<<<<<<<<<<
 *             value_ptr    = <uint8_t*>&double_value
 *             value_size   = sizeof(double)
 */
    __pyx_t_15 = __pyx_PyFloat_AsDouble(__pyx_v_value); if (unlikely((__pyx_t_15 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3362; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_double_value = __pyx_t_15;

    /* "pysam/calignmentfile.pyx":3363
 *         elif type_code == 'd':
 *             double_value = value
 *             value_ptr    = <uint8_t*>&double_value             # <<<<<<<<<<<<<<
 *             value_size   = sizeof(double)
 *         elif type_code == 'f':
 */
    __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_double_value));

    /* "pysam/calignmentfile.pyx":3364
 *             double_value = value
 *             value_ptr    = <uint8_t*>&double_value
 *             value_size   = sizeof(double)             # <<<<<<<<<<<<<<
 *         elif type_code == 'f':
 *             float_value  = value
 */
    __pyx_v_value_size = (sizeof(double));
    break;

    /* "pysam/calignmentfile.pyx":3365
 *             value_ptr    = <uint8_t*>&double_value
 *             value_size   = sizeof(double)
 *         elif type_code == 'f':             # <<<<<<<<<<<<<<
 *             float_value  = value
 *             value_ptr    = <uint8_t*>&float_value
 */
    case 'f':

    /* "pysam/calignmentfile.pyx":3366
 *             value_size   = sizeof(double)
 *         elif type_code == 'f':
 *             float_value  = value             # <<<<<<<<<<<<<<
 *             value_ptr    = <uint8_t*>&float_value
 *             value_size   = sizeof(float)
 */
    __pyx_t_16 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_16 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_float_value = __pyx_t_16;

    /* "pysam/calignmentfile.pyx":3367
 *         elif type_code == 'f':
 *             float_value  = value
 *             value_ptr    = <uint8_t*>&float_value             # <<<<<<<<<<<<<<
 *             value_size   = sizeof(float)
 *         else:
 */
    __pyx_v_value_ptr = ((uint8_t *)(&__pyx_v_float_value));

    /* "pysam/calignmentfile.pyx":3368
 *             float_value  = value
 *             value_ptr    = <uint8_t*>&float_value
 *             value_size   = sizeof(float)             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError('Unsupported value_type in set_option')
 */
    __pyx_v_value_size = (sizeof(float));
    break;
    default:

    /* "pysam/calignmentfile.pyx":3370
 *             value_size   = sizeof(float)
 *         else:
 *             raise ValueError('Unsupported value_type in set_option')             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__80, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    break;
  }

  /* "pysam/calignmentfile.pyx":3374
 * 
 *         bam_aux_append(src,
 *                        tag,             # <<<<<<<<<<<<<<
 *                        type_code,
 *                        value_size,
 */
  __pyx_t_17 = __Pyx_PyObject_AsString(__pyx_v_tag); if (unlikely((!__pyx_t_17) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3374; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3373
 * 
 * 
 *         bam_aux_append(src,             # <<<<<<<<<<<<<<
 *                        tag,
 *                        type_code,
 */
  bam_aux_append(__pyx_v_src, __pyx_t_17, __pyx_v_type_code, __pyx_v_value_size, __pyx_v_value_ptr);

  /* "pysam/calignmentfile.pyx":3305
 * 
 * 
 *     cpdef set_tag(self,             # <<<<<<<<<<<<<<
 *                   tag,
 *                   value,
 */

  /* 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_6);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.set_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_tag);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_23set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_22set_tag[] = "AlignedSegment.set_tag(self, tag, value, value_type=None, replace=True)\nsets a particular field *tag* to *value* in the optional alignment\n        section.\n\n        *value_type* describes the type of *value* that is to entered\n        into the alignment record.. It can be set explicitely to one\n        of the valid one-letter type codes. If unset, an appropriate\n        type will be chosen automatically.\n\n        An existing value of the same *tag* will be overwritten unless\n        replace is set to False. This is usually not recommened as a\n        tag may only appear once in the optional alignment section.\n\n        If *value* is None, the tag will be deleted.\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_23set_tag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tag = 0;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_v_value_type = 0;
  PyObject *__pyx_v_replace = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_tag (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_value,&__pyx_n_s_value_type,&__pyx_n_s_replace,0};
    PyObject* values[4] = {0,0,0,0};

    /* "pysam/calignmentfile.pyx":3308
 *                   tag,
 *                   value,
 *                   value_type=None,             # <<<<<<<<<<<<<<
 *                   replace=True):
 *         """sets a particular field *tag* to *value* in the optional alignment
 */
    values[2] = ((PyObject *)Py_None);

    /* "pysam/calignmentfile.pyx":3309
 *                   value,
 *                   value_type=None,
 *                   replace=True):             # <<<<<<<<<<<<<<
 *         """sets a particular field *tag* to *value* in the optional alignment
 *         section.
 */
    values[3] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("set_tag", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3305; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value_type);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_replace);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "set_tag") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3305; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_tag = values[0];
    __pyx_v_value = values[1];
    __pyx_v_value_type = values[2];
    __pyx_v_replace = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("set_tag", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3305; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.set_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_22set_tag(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace);

  /* "pysam/calignmentfile.pyx":3305
 * 
 * 
 *     cpdef set_tag(self,             # <<<<<<<<<<<<<<
 *                   tag,
 *                   value,
 */

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_22set_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_5pysam_14calignmentfile_14AlignedSegment_set_tag __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("set_tag", 0);
  __Pyx_TraceCall("set_tag", __pyx_f[0], 3305);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 2;
  __pyx_t_2.value_type = __pyx_v_value_type;
  __pyx_t_2.replace = __pyx_v_replace;
  __pyx_t_1 = __pyx_vtabptr_5pysam_14calignmentfile_AlignedSegment->set_tag(__pyx_v_self, __pyx_v_tag, __pyx_v_value, 1, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3305; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":3379
 *                        value_ptr)
 * 
 *     cpdef has_tag(self, tag):             # <<<<<<<<<<<<<<
 *         """returns true if the optional alignment section
 *         contains a given *tag*."""
 */

static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_25has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_14AlignedSegment_has_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch) {
  uint8_t *__pyx_v_v;
  PyObject *__pyx_v_btag = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  char const *__pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("has_tag", 0);
  __Pyx_TraceCall("has_tag", __pyx_f[0], 3379);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_has_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_25has_tag)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && 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);
        }
      }
      if (!__pyx_t_4) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_tag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
        __Pyx_INCREF(__pyx_v_tag);
        PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_tag);
        __Pyx_GIVEREF(__pyx_v_tag);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/calignmentfile.pyx":3384
 *         cdef uint8_t * v
 *         cdef int nvalues
 *         btag = _forceBytes(tag)             # <<<<<<<<<<<<<<
 *         v = bam_aux_get(self._delegate, btag)
 *         return v != NULL
 */
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile__forceBytes(__pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3384; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_btag = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":3385
 *         cdef int nvalues
 *         btag = _forceBytes(tag)
 *         v = bam_aux_get(self._delegate, btag)             # <<<<<<<<<<<<<<
 *         return v != NULL
 * 
 */
  __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_btag); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3385; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_v = bam_aux_get(__pyx_v_self->_delegate, __pyx_t_6);

  /* "pysam/calignmentfile.pyx":3386
 *         btag = _forceBytes(tag)
 *         v = bam_aux_get(self._delegate, btag)
 *         return v != NULL             # <<<<<<<<<<<<<<
 * 
 *     cpdef get_tag(self, tag):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyBool_FromLong((__pyx_v_v != NULL)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3379
 *                        value_ptr)
 * 
 *     cpdef has_tag(self, tag):             # <<<<<<<<<<<<<<
 *         """returns true if the optional alignment section
 *         contains a given *tag*."""
 */

  /* 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_AddTraceback("pysam.calignmentfile.AlignedSegment.has_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_btag);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_25has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_24has_tag[] = "AlignedSegment.has_tag(self, tag)\nreturns true if the optional alignment section\n        contains a given *tag*.";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_25has_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("has_tag (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_24has_tag(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tag));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_24has_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("has_tag", 0);
  __Pyx_TraceCall("has_tag", __pyx_f[0], 3379);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile_14AlignedSegment_has_tag(__pyx_v_self, __pyx_v_tag, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3379; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":3388
 *         return v != NULL
 * 
 *     cpdef get_tag(self, tag):             # <<<<<<<<<<<<<<
 *         """retrieves data from the optional alignment section
 *         given a two-letter *tag* denoting the field.
 */

static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_27get_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_14AlignedSegment_get_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, int __pyx_skip_dispatch) {
  uint8_t *__pyx_v_v;
  CYTHON_UNUSED int __pyx_v_nvalues;
  PyObject *__pyx_v_btag = NULL;
  PyObject *__pyx_v_auxtype = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_bytesize = NULL;
  PyObject *__pyx_v_values = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  char const *__pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("get_tag", 0);
  __Pyx_TraceCall("get_tag", __pyx_f[0], 3388);
  /* Check if called by wrapper */
  if (unlikely(__pyx_skip_dispatch)) ;
  /* Check if overridden in Python */
  else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) {
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_27get_tag)) {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1; __pyx_t_4 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && 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);
        }
      }
      if (!__pyx_t_4) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_tag); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
        __Pyx_INCREF(__pyx_v_tag);
        PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_tag);
        __Pyx_GIVEREF(__pyx_v_tag);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/calignmentfile.pyx":3401
 *         cdef uint8_t * v
 *         cdef int nvalues
 *         btag = _forceBytes(tag)             # <<<<<<<<<<<<<<
 *         v = bam_aux_get(self._delegate, btag)
 *         if v == NULL:
 */
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile__forceBytes(__pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_btag = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":3402
 *         cdef int nvalues
 *         btag = _forceBytes(tag)
 *         v = bam_aux_get(self._delegate, btag)             # <<<<<<<<<<<<<<
 *         if v == NULL:
 *             raise KeyError("tag '%s' not present" % tag)
 */
  __pyx_t_6 = __Pyx_PyObject_AsString(__pyx_v_btag); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_v = bam_aux_get(__pyx_v_self->_delegate, __pyx_t_6);

  /* "pysam/calignmentfile.pyx":3403
 *         btag = _forceBytes(tag)
 *         v = bam_aux_get(self._delegate, btag)
 *         if v == NULL:             # <<<<<<<<<<<<<<
 *             raise KeyError("tag '%s' not present" % tag)
 *         auxtype = chr(v[0])
 */
  __pyx_t_7 = ((__pyx_v_v == NULL) != 0);
  if (__pyx_t_7) {

    /* "pysam/calignmentfile.pyx":3404
 *         v = bam_aux_get(self._delegate, btag)
 *         if v == NULL:
 *             raise KeyError("tag '%s' not present" % tag)             # <<<<<<<<<<<<<<
 *         auxtype = chr(v[0])
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 */
    __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_tag_s_not_present, __pyx_v_tag); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":3405
 *         if v == NULL:
 *             raise KeyError("tag '%s' not present" % tag)
 *         auxtype = chr(v[0])             # <<<<<<<<<<<<<<
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 *             return <int>bam_aux2i(v)
 */
  __pyx_t_1 = __Pyx_PyInt_From_uint8_t((__pyx_v_v[0])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_chr, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_auxtype = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":3406
 *             raise KeyError("tag '%s' not present" % tag)
 *         auxtype = chr(v[0])
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':             # <<<<<<<<<<<<<<
 *             return <int>bam_aux2i(v)
 *         elif auxtype == 'i' or auxtype == 'I':
 */
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_c, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_8) {
  } else {
    __pyx_t_7 = __pyx_t_8;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_C, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_8) {
  } else {
    __pyx_t_7 = __pyx_t_8;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_s_2, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_8) {
  } else {
    __pyx_t_7 = __pyx_t_8;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_S, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = __pyx_t_8;
  __pyx_L5_bool_binop_done:;
  if (__pyx_t_7) {

    /* "pysam/calignmentfile.pyx":3407
 *         auxtype = chr(v[0])
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 *             return <int>bam_aux2i(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'i' or auxtype == 'I':
 *             return <int32_t>bam_aux2i(v)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3408
 *         if auxtype == 'c' or auxtype == 'C' or auxtype == 's' or auxtype == 'S':
 *             return <int>bam_aux2i(v)
 *         elif auxtype == 'i' or auxtype == 'I':             # <<<<<<<<<<<<<<
 *             return <int32_t>bam_aux2i(v)
 *         elif auxtype == 'f' or auxtype == 'F':
 */
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_i, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_8) {
  } else {
    __pyx_t_7 = __pyx_t_8;
    goto __pyx_L9_bool_binop_done;
  }
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_I, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = __pyx_t_8;
  __pyx_L9_bool_binop_done:;
  if (__pyx_t_7) {

    /* "pysam/calignmentfile.pyx":3409
 *             return <int>bam_aux2i(v)
 *         elif auxtype == 'i' or auxtype == 'I':
 *             return <int32_t>bam_aux2i(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'f' or auxtype == 'F':
 *             return <float>bam_aux2f(v)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyInt_From_int32_t(((int32_t)bam_aux2i(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3410
 *         elif auxtype == 'i' or auxtype == 'I':
 *             return <int32_t>bam_aux2i(v)
 *         elif auxtype == 'f' or auxtype == 'F':             # <<<<<<<<<<<<<<
 *             return <float>bam_aux2f(v)
 *         elif auxtype == 'd' or auxtype == 'D':
 */
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_f, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_8) {
  } else {
    __pyx_t_7 = __pyx_t_8;
    goto __pyx_L11_bool_binop_done;
  }
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_F, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = __pyx_t_8;
  __pyx_L11_bool_binop_done:;
  if (__pyx_t_7) {

    /* "pysam/calignmentfile.pyx":3411
 *             return <int32_t>bam_aux2i(v)
 *         elif auxtype == 'f' or auxtype == 'F':
 *             return <float>bam_aux2f(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'd' or auxtype == 'D':
 *             return <double>bam_aux2f(v)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3411; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3412
 *         elif auxtype == 'f' or auxtype == 'F':
 *             return <float>bam_aux2f(v)
 *         elif auxtype == 'd' or auxtype == 'D':             # <<<<<<<<<<<<<<
 *             return <double>bam_aux2f(v)
 *         elif auxtype == 'A':
 */
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_d, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (!__pyx_t_8) {
  } else {
    __pyx_t_7 = __pyx_t_8;
    goto __pyx_L13_bool_binop_done;
  }
  __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_D, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3412; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = __pyx_t_8;
  __pyx_L13_bool_binop_done:;
  if (__pyx_t_7) {

    /* "pysam/calignmentfile.pyx":3413
 *             return <float>bam_aux2f(v)
 *         elif auxtype == 'd' or auxtype == 'D':
 *             return <double>bam_aux2f(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'A':
 *             # there might a more efficient way
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyFloat_FromDouble(((double)bam_aux2f(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3414
 *         elif auxtype == 'd' or auxtype == 'D':
 *             return <double>bam_aux2f(v)
 *         elif auxtype == 'A':             # <<<<<<<<<<<<<<
 *             # there might a more efficient way
 *             # to convert a char into a string
 */
  __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_A, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_7) {

    /* "pysam/calignmentfile.pyx":3417
 *             # there might a more efficient way
 *             # to convert a char into a string
 *             return '%c' % <char>bam_aux2A(v)             # <<<<<<<<<<<<<<
 *         elif auxtype == 'Z':
 *             return _charptr_to_str(<char*>bam_aux2Z(v))
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyInt_From_char(((char)bam_aux2A(__pyx_v_v))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_c_2, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3418
 *             # to convert a char into a string
 *             return '%c' % <char>bam_aux2A(v)
 *         elif auxtype == 'Z':             # <<<<<<<<<<<<<<
 *             return _charptr_to_str(<char*>bam_aux2Z(v))
 *         elif auxtype == 'B':
 */
  __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_Z, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3418; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_7) {

    /* "pysam/calignmentfile.pyx":3419
 *             return '%c' % <char>bam_aux2A(v)
 *         elif auxtype == 'Z':
 *             return _charptr_to_str(<char*>bam_aux2Z(v))             # <<<<<<<<<<<<<<
 *         elif auxtype == 'B':
 *             bytesize, nvalues, values = convertBinaryTagToList(v + 1)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __pyx_f_5pysam_14calignmentfile__charptr_to_str(((char *)bam_aux2Z(__pyx_v_v))); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3419; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3420
 *         elif auxtype == 'Z':
 *             return _charptr_to_str(<char*>bam_aux2Z(v))
 *         elif auxtype == 'B':             # <<<<<<<<<<<<<<
 *             bytesize, nvalues, values = convertBinaryTagToList(v + 1)
 *             return values
 */
  __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_v_auxtype, __pyx_n_s_B, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_7) {

    /* "pysam/calignmentfile.pyx":3421
 *             return _charptr_to_str(<char*>bam_aux2Z(v))
 *         elif auxtype == 'B':
 *             bytesize, nvalues, values = convertBinaryTagToList(v + 1)             # <<<<<<<<<<<<<<
 *             return values
 *         else:
 */
    __pyx_t_2 = __pyx_f_5pysam_14calignmentfile_convertBinaryTagToList((__pyx_v_v + 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
      PyObject* sequence = __pyx_t_2;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 3)) {
        if (size > 3) __Pyx_RaiseTooManyValuesError(3);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); 
      } else {
        __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
        __pyx_t_5 = PyList_GET_ITEM(sequence, 2); 
      }
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      #else
      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext;
      index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L15_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      index = 1; __pyx_t_3 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L15_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      index = 2; __pyx_t_5 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_5)) goto __pyx_L15_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_5);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_4), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_9 = NULL;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      goto __pyx_L16_unpacking_done;
      __pyx_L15_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_9 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L16_unpacking_done:;
    }
    __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_bytesize = __pyx_t_1;
    __pyx_t_1 = 0;
    __pyx_v_nvalues = __pyx_t_10;
    __pyx_v_values = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "pysam/calignmentfile.pyx":3422
 *         elif auxtype == 'B':
 *             bytesize, nvalues, values = convertBinaryTagToList(v + 1)
 *             return values             # <<<<<<<<<<<<<<
 *         else:
 *             raise ValueError("unknown auxilliary type '%s'" % auxtype)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(__pyx_v_values);
    __pyx_r = __pyx_v_values;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":3424
 *             return values
 *         else:
 *             raise ValueError("unknown auxilliary type '%s'" % auxtype)             # <<<<<<<<<<<<<<
 * 
 *     def get_tags(self, with_value_type=False):
 */
    __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_unknown_auxilliary_type_s, __pyx_v_auxtype); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":3388
 *         return v != NULL
 * 
 *     cpdef get_tag(self, tag):             # <<<<<<<<<<<<<<
 *         """retrieves data from the optional alignment section
 *         given a two-letter *tag* denoting the field.
 */

  /* 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_AddTraceback("pysam.calignmentfile.AlignedSegment.get_tag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_btag);
  __Pyx_XDECREF(__pyx_v_auxtype);
  __Pyx_XDECREF(__pyx_v_bytesize);
  __Pyx_XDECREF(__pyx_v_values);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_27get_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_26get_tag[] = "AlignedSegment.get_tag(self, tag)\nretrieves data from the optional alignment section\n        given a two-letter *tag* denoting the field.\n\n        If *tag* is not present, a KeyError is raised.\n\n        The returned value is cast into an appropriate python type.\n\n        This method is the fastest way to access the optional\n        alignment section if only few tags need to be retrieved.\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_27get_tag(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_tag (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_26get_tag(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tag));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_26get_tag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("get_tag", 0);
  __Pyx_TraceCall("get_tag", __pyx_f[0], 3388);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile_14AlignedSegment_get_tag(__pyx_v_self, __pyx_v_tag, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":3426
 *             raise ValueError("unknown auxilliary type '%s'" % auxtype)
 * 
 *     def get_tags(self, with_value_type=False):             # <<<<<<<<<<<<<<
 *         """the fields in the optional aligment section.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_29get_tags(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_28get_tags[] = "AlignedSegment.get_tags(self, with_value_type=False)\nthe fields in the optional aligment section.\n\n        Returns a list of all fields in the optional\n        alignment section. Values are converted to appropriate python\n        values. For example:\n\n        [(NM, 2), (RG, \"GJP00TM04\")]\n\n        If *with_value_type* is set, the value type as encode in\n        the AlignedSegment record will be returned as well:\n\n        [(NM, 2, \"i\"), (RG, \"GJP00TM04\", \"Z\")]\n\n        This method will convert all values in the optional alignment\n        section. When getting only one or few tags, please see\n        :meth:`get_tag` for a quicker way to achieve this.\n\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_29get_tags(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  CYTHON_UNUSED PyObject *__pyx_v_with_value_type = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_tags (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_with_value_type,0};
    PyObject* values[1] = {0};
    values[0] = ((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  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_with_value_type);
          if (value) { values[0] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_tags") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3426; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_with_value_type = values[0];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("get_tags", 0, 0, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3426; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.get_tags", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_28get_tags(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), __pyx_v_with_value_type);

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_28get_tags(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_with_value_type) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_s;
  char __pyx_v_auxtag[3];
  char __pyx_v_auxtype;
  uint8_t __pyx_v_byte_size;
  int32_t __pyx_v_nvalues;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_value = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  uint8_t __pyx_t_10;
  int32_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("get_tags", 0);
  __Pyx_TraceCall("get_tags", __pyx_f[0], 3426);

  /* "pysam/calignmentfile.pyx":3454
 *         cdef int32_t nvalues
 * 
 *         src = self._delegate             # <<<<<<<<<<<<<<
 *         if src.l_data == 0:
 *             return []
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":3455
 * 
 *         src = self._delegate
 *         if src.l_data == 0:             # <<<<<<<<<<<<<<
 *             return []
 *         s = pysam_bam_get_aux(src)
 */
  __pyx_t_2 = ((__pyx_v_src->l_data == 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":3456
 *         src = self._delegate
 *         if src.l_data == 0:
 *             return []             # <<<<<<<<<<<<<<
 *         s = pysam_bam_get_aux(src)
 *         result = []
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3457
 *         if src.l_data == 0:
 *             return []
 *         s = pysam_bam_get_aux(src)             # <<<<<<<<<<<<<<
 *         result = []
 *         auxtag[2] = 0
 */
  __pyx_v_s = pysam_bam_get_aux(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":3458
 *             return []
 *         s = pysam_bam_get_aux(src)
 *         result = []             # <<<<<<<<<<<<<<
 *         auxtag[2] = 0
 *         while s < (src.data + src.l_data):
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysam/calignmentfile.pyx":3459
 *         s = pysam_bam_get_aux(src)
 *         result = []
 *         auxtag[2] = 0             # <<<<<<<<<<<<<<
 *         while s < (src.data + src.l_data):
 *             # get tag
 */
  (__pyx_v_auxtag[2]) = 0;

  /* "pysam/calignmentfile.pyx":3460
 *         result = []
 *         auxtag[2] = 0
 *         while s < (src.data + src.l_data):             # <<<<<<<<<<<<<<
 *             # get tag
 *             auxtag[0] = s[0]
 */
  while (1) {
    __pyx_t_2 = ((__pyx_v_s < (__pyx_v_src->data + __pyx_v_src->l_data)) != 0);
    if (!__pyx_t_2) break;

    /* "pysam/calignmentfile.pyx":3462
 *         while s < (src.data + src.l_data):
 *             # get tag
 *             auxtag[0] = s[0]             # <<<<<<<<<<<<<<
 *             auxtag[1] = s[1]
 *             s += 2
 */
    (__pyx_v_auxtag[0]) = (__pyx_v_s[0]);

    /* "pysam/calignmentfile.pyx":3463
 *             # get tag
 *             auxtag[0] = s[0]
 *             auxtag[1] = s[1]             # <<<<<<<<<<<<<<
 *             s += 2
 *             auxtype = s[0]
 */
    (__pyx_v_auxtag[1]) = (__pyx_v_s[1]);

    /* "pysam/calignmentfile.pyx":3464
 *             auxtag[0] = s[0]
 *             auxtag[1] = s[1]
 *             s += 2             # <<<<<<<<<<<<<<
 *             auxtype = s[0]
 *             if auxtype in ('c', 'C'):
 */
    __pyx_v_s = (__pyx_v_s + 2);

    /* "pysam/calignmentfile.pyx":3465
 *             auxtag[1] = s[1]
 *             s += 2
 *             auxtype = s[0]             # <<<<<<<<<<<<<<
 *             if auxtype in ('c', 'C'):
 *                 value = <int>bam_aux2i(s)
 */
    __pyx_v_auxtype = (__pyx_v_s[0]);

    /* "pysam/calignmentfile.pyx":3488
 *                 # +1 for NULL terminated string
 *                 s += len(value) + 1
 *             elif auxtype == 'B':             # <<<<<<<<<<<<<<
 *                 s += 1
 *                 byte_size, nvalues, value = convertBinaryTagToList(s)
 */
    switch (__pyx_v_auxtype) {

      /* "pysam/calignmentfile.pyx":3466
 *             s += 2
 *             auxtype = s[0]
 *             if auxtype in ('c', 'C'):             # <<<<<<<<<<<<<<
 *                 value = <int>bam_aux2i(s)
 *                 s += 1
 */
      case 'c':
      case 'C':

      /* "pysam/calignmentfile.pyx":3467
 *             auxtype = s[0]
 *             if auxtype in ('c', 'C'):
 *                 value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                 s += 1
 *             elif auxtype in ('s', 'S'):
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignmentfile.pyx":3468
 *             if auxtype in ('c', 'C'):
 *                 value = <int>bam_aux2i(s)
 *                 s += 1             # <<<<<<<<<<<<<<
 *             elif auxtype in ('s', 'S'):
 *                 value = <int>bam_aux2i(s)
 */
      __pyx_v_s = (__pyx_v_s + 1);
      break;

      /* "pysam/calignmentfile.pyx":3469
 *                 value = <int>bam_aux2i(s)
 *                 s += 1
 *             elif auxtype in ('s', 'S'):             # <<<<<<<<<<<<<<
 *                 value = <int>bam_aux2i(s)
 *                 s += 2
 */
      case 's':
      case 'S':

      /* "pysam/calignmentfile.pyx":3470
 *                 s += 1
 *             elif auxtype in ('s', 'S'):
 *                 value = <int>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                 s += 2
 *             elif auxtype in ('i', 'I'):
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(((int)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3470; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignmentfile.pyx":3471
 *             elif auxtype in ('s', 'S'):
 *                 value = <int>bam_aux2i(s)
 *                 s += 2             # <<<<<<<<<<<<<<
 *             elif auxtype in ('i', 'I'):
 *                 value = <int32_t>bam_aux2i(s)
 */
      __pyx_v_s = (__pyx_v_s + 2);
      break;

      /* "pysam/calignmentfile.pyx":3472
 *                 value = <int>bam_aux2i(s)
 *                 s += 2
 *             elif auxtype in ('i', 'I'):             # <<<<<<<<<<<<<<
 *                 value = <int32_t>bam_aux2i(s)
 *                 s += 4
 */
      case 'i':
      case 'I':

      /* "pysam/calignmentfile.pyx":3473
 *                 s += 2
 *             elif auxtype in ('i', 'I'):
 *                 value = <int32_t>bam_aux2i(s)             # <<<<<<<<<<<<<<
 *                 s += 4
 *             elif auxtype == 'f':
 */
      __pyx_t_3 = __Pyx_PyInt_From_int32_t(((int32_t)bam_aux2i(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3473; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignmentfile.pyx":3474
 *             elif auxtype in ('i', 'I'):
 *                 value = <int32_t>bam_aux2i(s)
 *                 s += 4             # <<<<<<<<<<<<<<
 *             elif auxtype == 'f':
 *                 value = <float>bam_aux2f(s)
 */
      __pyx_v_s = (__pyx_v_s + 4);
      break;

      /* "pysam/calignmentfile.pyx":3475
 *                 value = <int32_t>bam_aux2i(s)
 *                 s += 4
 *             elif auxtype == 'f':             # <<<<<<<<<<<<<<
 *                 value = <float>bam_aux2f(s)
 *                 s += 4
 */
      case 'f':

      /* "pysam/calignmentfile.pyx":3476
 *                 s += 4
 *             elif auxtype == 'f':
 *                 value = <float>bam_aux2f(s)             # <<<<<<<<<<<<<<
 *                 s += 4
 *             elif auxtype == 'd':
 */
      __pyx_t_3 = PyFloat_FromDouble(((float)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3476; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignmentfile.pyx":3477
 *             elif auxtype == 'f':
 *                 value = <float>bam_aux2f(s)
 *                 s += 4             # <<<<<<<<<<<<<<
 *             elif auxtype == 'd':
 *                 value = <double>bam_aux2f(s)
 */
      __pyx_v_s = (__pyx_v_s + 4);
      break;

      /* "pysam/calignmentfile.pyx":3478
 *                 value = <float>bam_aux2f(s)
 *                 s += 4
 *             elif auxtype == 'd':             # <<<<<<<<<<<<<<
 *                 value = <double>bam_aux2f(s)
 *                 s += 8
 */
      case 'd':

      /* "pysam/calignmentfile.pyx":3479
 *                 s += 4
 *             elif auxtype == 'd':
 *                 value = <double>bam_aux2f(s)             # <<<<<<<<<<<<<<
 *                 s += 8
 *             elif auxtype == 'A':
 */
      __pyx_t_3 = PyFloat_FromDouble(((double)bam_aux2f(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3479; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "pysam/calignmentfile.pyx":3480
 *             elif auxtype == 'd':
 *                 value = <double>bam_aux2f(s)
 *                 s += 8             # <<<<<<<<<<<<<<
 *             elif auxtype == 'A':
 *                 value = "%c" % <char>bam_aux2A(s)
 */
      __pyx_v_s = (__pyx_v_s + 8);
      break;

      /* "pysam/calignmentfile.pyx":3481
 *                 value = <double>bam_aux2f(s)
 *                 s += 8
 *             elif auxtype == 'A':             # <<<<<<<<<<<<<<
 *                 value = "%c" % <char>bam_aux2A(s)
 *                 s += 1
 */
      case 'A':

      /* "pysam/calignmentfile.pyx":3482
 *                 s += 8
 *             elif auxtype == 'A':
 *                 value = "%c" % <char>bam_aux2A(s)             # <<<<<<<<<<<<<<
 *                 s += 1
 *             elif auxtype in ('Z', 'H'):
 */
      __pyx_t_3 = __Pyx_PyInt_From_char(((char)bam_aux2A(__pyx_v_s))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_c_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3482; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "pysam/calignmentfile.pyx":3483
 *             elif auxtype == 'A':
 *                 value = "%c" % <char>bam_aux2A(s)
 *                 s += 1             # <<<<<<<<<<<<<<
 *             elif auxtype in ('Z', 'H'):
 *                 value = _charptr_to_str(<char*>bam_aux2Z(s))
 */
      __pyx_v_s = (__pyx_v_s + 1);
      break;

      /* "pysam/calignmentfile.pyx":3484
 *                 value = "%c" % <char>bam_aux2A(s)
 *                 s += 1
 *             elif auxtype in ('Z', 'H'):             # <<<<<<<<<<<<<<
 *                 value = _charptr_to_str(<char*>bam_aux2Z(s))
 *                 # +1 for NULL terminated string
 */
      case 'Z':
      case 'H':

      /* "pysam/calignmentfile.pyx":3485
 *                 s += 1
 *             elif auxtype in ('Z', 'H'):
 *                 value = _charptr_to_str(<char*>bam_aux2Z(s))             # <<<<<<<<<<<<<<
 *                 # +1 for NULL terminated string
 *                 s += len(value) + 1
 */
      __pyx_t_4 = __pyx_f_5pysam_14calignmentfile__charptr_to_str(((char *)bam_aux2Z(__pyx_v_s))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "pysam/calignmentfile.pyx":3487
 *                 value = _charptr_to_str(<char*>bam_aux2Z(s))
 *                 # +1 for NULL terminated string
 *                 s += len(value) + 1             # <<<<<<<<<<<<<<
 *             elif auxtype == 'B':
 *                 s += 1
 */
      __pyx_t_5 = PyObject_Length(__pyx_v_value); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_s = (__pyx_v_s + (__pyx_t_5 + 1));
      break;

      /* "pysam/calignmentfile.pyx":3488
 *                 # +1 for NULL terminated string
 *                 s += len(value) + 1
 *             elif auxtype == 'B':             # <<<<<<<<<<<<<<
 *                 s += 1
 *                 byte_size, nvalues, value = convertBinaryTagToList(s)
 */
      case 'B':

      /* "pysam/calignmentfile.pyx":3489
 *                 s += len(value) + 1
 *             elif auxtype == 'B':
 *                 s += 1             # <<<<<<<<<<<<<<
 *                 byte_size, nvalues, value = convertBinaryTagToList(s)
 *                 # 5 for 1 char and 1 int
 */
      __pyx_v_s = (__pyx_v_s + 1);

      /* "pysam/calignmentfile.pyx":3490
 *             elif auxtype == 'B':
 *                 s += 1
 *                 byte_size, nvalues, value = convertBinaryTagToList(s)             # <<<<<<<<<<<<<<
 *                 # 5 for 1 char and 1 int
 *                 s += 5 + (nvalues * byte_size) - 1
 */
      __pyx_t_4 = __pyx_f_5pysam_14calignmentfile_convertBinaryTagToList(__pyx_v_s); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
        PyObject* sequence = __pyx_t_4;
        #if CYTHON_COMPILING_IN_CPYTHON
        Py_ssize_t size = Py_SIZE(sequence);
        #else
        Py_ssize_t size = PySequence_Size(sequence);
        #endif
        if (unlikely(size != 3)) {
          if (size > 3) __Pyx_RaiseTooManyValuesError(3);
          else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        #if CYTHON_COMPILING_IN_CPYTHON
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
          __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); 
        } else {
          __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
          __pyx_t_7 = PyList_GET_ITEM(sequence, 2); 
        }
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        #else
        __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_7);
        #endif
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_8 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
        index = 0; __pyx_t_3 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        index = 1; __pyx_t_6 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_6)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 2; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_7);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        goto __pyx_L7_unpacking_done;
        __pyx_L6_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_L7_unpacking_done:;
      }
      __pyx_t_10 = __Pyx_PyInt_As_uint8_t(__pyx_t_3); if (unlikely((__pyx_t_10 == (uint8_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_11 = __Pyx_PyInt_As_int32_t(__pyx_t_6); if (unlikely((__pyx_t_11 == (int32_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_v_byte_size = __pyx_t_10;
      __pyx_v_nvalues = __pyx_t_11;
      __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_7);
      __pyx_t_7 = 0;

      /* "pysam/calignmentfile.pyx":3492
 *                 byte_size, nvalues, value = convertBinaryTagToList(s)
 *                 # 5 for 1 char and 1 int
 *                 s += 5 + (nvalues * byte_size) - 1             # <<<<<<<<<<<<<<
 *             else:
 *                 raise KeyError("unknown type '%s'" % auxtype)
 */
      __pyx_v_s = (__pyx_v_s + ((5 + (__pyx_v_nvalues * __pyx_v_byte_size)) - 1));
      break;
      default:

      /* "pysam/calignmentfile.pyx":3494
 *                 s += 5 + (nvalues * byte_size) - 1
 *             else:
 *                 raise KeyError("unknown type '%s'" % auxtype)             # <<<<<<<<<<<<<<
 * 
 *             s += 1
 */
      __pyx_t_4 = __Pyx_PyInt_From_char(__pyx_v_auxtype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_unknown_type_s, __pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_7, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3494; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      break;
    }

    /* "pysam/calignmentfile.pyx":3496
 *                 raise KeyError("unknown type '%s'" % auxtype)
 * 
 *             s += 1             # <<<<<<<<<<<<<<
 * 
 *             result.append((_charptr_to_str(auxtag), value))
 */
    __pyx_v_s = (__pyx_v_s + 1);

    /* "pysam/calignmentfile.pyx":3498
 *             s += 1
 * 
 *             result.append((_charptr_to_str(auxtag), value))             # <<<<<<<<<<<<<<
 * 
 *         return result
 */
    __pyx_t_7 = __pyx_f_5pysam_14calignmentfile__charptr_to_str(__pyx_v_auxtag); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_value);
    __Pyx_GIVEREF(__pyx_v_value);
    __pyx_t_7 = 0;
    __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_4); if (unlikely(__pyx_t_12 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }

  /* "pysam/calignmentfile.pyx":3500
 *             result.append((_charptr_to_str(auxtag), value))
 * 
 *         return result             # <<<<<<<<<<<<<<
 * 
 *     def set_tags(self, tags):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3426
 *             raise ValueError("unknown auxilliary type '%s'" % auxtype)
 * 
 *     def get_tags(self, with_value_type=False):             # <<<<<<<<<<<<<<
 *         """the fields in the optional aligment section.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.get_tags", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_value);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3502
 *         return result
 * 
 *     def set_tags(self, tags):             # <<<<<<<<<<<<<<
 *         """sets the fields in the optional alignmest section with
 *         a list of (tag, value) tuples.
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_31set_tags(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_30set_tags[] = "AlignedSegment.set_tags(self, tags)\nsets the fields in the optional alignmest section with\n        a list of (tag, value) tuples.\n\n        The :term:`value type` of the values is determined from the\n        python type. Optionally, a type may be given explicitely as\n        a third value in the tuple, For example:\n\n        x.set_tags([(NM, 2, \"i\"), (RG, \"GJP00TM04\", \"Z\")]\n\n        This method will not enforce the rule that the same tag may appear\n        only once in the optional alignment section.\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_31set_tags(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_tags (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_30set_tags(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tags));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_30set_tags(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags) {
  bam1_t *__pyx_v_src;
  uint8_t *__pyx_v_s;
  char *__pyx_v_temp;
  int __pyx_v_new_size;
  int __pyx_v_old_size;
  PyObject *__pyx_v_fmt = NULL;
  PyObject *__pyx_v_args = NULL;
  PyObject *__pyx_v_buffer = NULL;
  PyObject *__pyx_v_p = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  bam1_t *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *(*__pyx_t_10)(PyObject *);
  int __pyx_t_11;
  PyObject *__pyx_t_12 = NULL;
  char *__pyx_t_13;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("set_tags", 0);
  __Pyx_TraceCall("set_tags", __pyx_f[0], 3502);

  /* "pysam/calignmentfile.pyx":3519
 *         cdef uint8_t * s
 *         cdef char * temp
 *         cdef int new_size = 0             # <<<<<<<<<<<<<<
 *         cdef int old_size
 *         src = self._delegate
 */
  __pyx_v_new_size = 0;

  /* "pysam/calignmentfile.pyx":3521
 *         cdef int new_size = 0
 *         cdef int old_size
 *         src = self._delegate             # <<<<<<<<<<<<<<
 * 
 *         # convert and pack the data
 */
  __pyx_t_1 = __pyx_v_self->_delegate;
  __pyx_v_src = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":3524
 * 
 *         # convert and pack the data
 *         if tags is not None and len(tags) > 0:             # <<<<<<<<<<<<<<
 *             fmt, args =_pack_tags(tags)
 *             new_size = struct.calcsize(fmt)
 */
  __pyx_t_3 = (__pyx_v_tags != Py_None);
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = PyObject_Length(__pyx_v_tags); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3524; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = ((__pyx_t_5 > 0) != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":3525
 *         # convert and pack the data
 *         if tags is not None and len(tags) > 0:
 *             fmt, args =_pack_tags(tags)             # <<<<<<<<<<<<<<
 *             new_size = struct.calcsize(fmt)
 *             buffer = ctypes.create_string_buffer(new_size)
 */
    __pyx_t_6 = __pyx_f_5pysam_14calignmentfile__pack_tags(__pyx_v_tags); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
      PyObject* sequence = __pyx_t_6;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(__pyx_t_8);
      #else
      __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      #endif
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_9 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_10 = Py_TYPE(__pyx_t_9)->tp_iternext;
      index = 0; __pyx_t_7 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_7);
      index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L6_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_8);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = NULL;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      goto __pyx_L7_unpacking_done;
      __pyx_L6_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_10 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L7_unpacking_done:;
    }
    __pyx_v_fmt = __pyx_t_7;
    __pyx_t_7 = 0;
    __pyx_v_args = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "pysam/calignmentfile.pyx":3526
 *         if tags is not None and len(tags) > 0:
 *             fmt, args =_pack_tags(tags)
 *             new_size = struct.calcsize(fmt)             # <<<<<<<<<<<<<<
 *             buffer = ctypes.create_string_buffer(new_size)
 *             struct.pack_into(fmt,
 */
    __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_calcsize); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_8) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_fmt); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
    } else {
      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = NULL;
      __Pyx_INCREF(__pyx_v_fmt);
      PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_fmt);
      __Pyx_GIVEREF(__pyx_v_fmt);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_11 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_11 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3526; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_new_size = __pyx_t_11;

    /* "pysam/calignmentfile.pyx":3527
 *             fmt, args =_pack_tags(tags)
 *             new_size = struct.calcsize(fmt)
 *             buffer = ctypes.create_string_buffer(new_size)             # <<<<<<<<<<<<<<
 *             struct.pack_into(fmt,
 *                              buffer,
 */
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_ctypes); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_create_string_buffer); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_new_size); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    if (!__pyx_t_8) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_6);
    } else {
      __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_12);
      PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = NULL;
      PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    }
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_v_buffer = __pyx_t_6;
    __pyx_t_6 = 0;

    /* "pysam/calignmentfile.pyx":3528
 *             new_size = struct.calcsize(fmt)
 *             buffer = ctypes.create_string_buffer(new_size)
 *             struct.pack_into(fmt,             # <<<<<<<<<<<<<<
 *                              buffer,
 *                              0,
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_struct); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_pack_into); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "pysam/calignmentfile.pyx":3529
 *             buffer = ctypes.create_string_buffer(new_size)
 *             struct.pack_into(fmt,
 *                              buffer,             # <<<<<<<<<<<<<<
 *                              0,
 *                              *args)
 */
    __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_fmt);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_fmt);
    __Pyx_GIVEREF(__pyx_v_fmt);
    __Pyx_INCREF(__pyx_v_buffer);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_buffer);
    __Pyx_GIVEREF(__pyx_v_buffer);
    __Pyx_INCREF(__pyx_int_0);
    PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);

    /* "pysam/calignmentfile.pyx":3528
 *             new_size = struct.calcsize(fmt)
 *             buffer = ctypes.create_string_buffer(new_size)
 *             struct.pack_into(fmt,             # <<<<<<<<<<<<<<
 *                              buffer,
 *                              0,
 */
    __pyx_t_12 = PySequence_Tuple(__pyx_v_args); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_7 = PyNumber_Add(__pyx_t_6, __pyx_t_12); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3528; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":3536
 *         # If total_size == 0, the aux field will be
 *         # empty
 *         old_size = pysam_bam_get_l_aux(src)             # <<<<<<<<<<<<<<
 *         pysam_bam_update(src,
 *                          old_size,
 */
  __pyx_v_old_size = pysam_bam_get_l_aux(__pyx_v_src);

  /* "pysam/calignmentfile.pyx":3537
 *         # empty
 *         old_size = pysam_bam_get_l_aux(src)
 *         pysam_bam_update(src,             # <<<<<<<<<<<<<<
 *                          old_size,
 *                          new_size,
 */
  pysam_bam_update(__pyx_v_src, __pyx_v_old_size, __pyx_v_new_size, pysam_bam_get_aux(__pyx_v_src));

  /* "pysam/calignmentfile.pyx":3543
 * 
 *         # copy data only if there is any
 *         if new_size > 0:             # <<<<<<<<<<<<<<
 * 
 *             # get location of new data
 */
  __pyx_t_2 = ((__pyx_v_new_size > 0) != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":3546
 * 
 *             # get location of new data
 *             s = pysam_bam_get_aux(src)             # <<<<<<<<<<<<<<
 * 
 *             # check if there is direct path from buffer.raw to tmp
 */
    __pyx_v_s = pysam_bam_get_aux(__pyx_v_src);

    /* "pysam/calignmentfile.pyx":3549
 * 
 *             # check if there is direct path from buffer.raw to tmp
 *             p = buffer.raw             # <<<<<<<<<<<<<<
 *             # create handle to make sure buffer stays alive long
 *             # enough for memcpy, see issue 129
 */
    if (unlikely(!__pyx_v_buffer)) { __Pyx_RaiseUnboundLocalError("buffer"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3549; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_buffer, __pyx_n_s_raw); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_v_p = __pyx_t_12;
    __pyx_t_12 = 0;

    /* "pysam/calignmentfile.pyx":3552
 *             # create handle to make sure buffer stays alive long
 *             # enough for memcpy, see issue 129
 *             temp = p             # <<<<<<<<<<<<<<
 *             memcpy(s, temp, new_size)
 * 
 */
    __pyx_t_13 = __Pyx_PyObject_AsString(__pyx_v_p); if (unlikely((!__pyx_t_13) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_temp = __pyx_t_13;

    /* "pysam/calignmentfile.pyx":3553
 *             # enough for memcpy, see issue 129
 *             temp = p
 *             memcpy(s, temp, new_size)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    memcpy(__pyx_v_s, __pyx_v_temp, __pyx_v_new_size);
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "pysam/calignmentfile.pyx":3502
 *         return result
 * 
 *     def set_tags(self, tags):             # <<<<<<<<<<<<<<
 *         """sets the fields in the optional alignmest section with
 *         a list of (tag, value) tuples.
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.set_tags", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fmt);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_buffer);
  __Pyx_XDECREF(__pyx_v_p);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3570
 *     ########################################################
 *     property qname:
 *         def __get__(self): return self.query_name             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.query_name = v
 *     property tid:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qname_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qname_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5qname___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5qname___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3570);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":3571
 *     property qname:
 *         def __get__(self): return self.query_name
 *         def __set__(self, v): self.query_name = v             # <<<<<<<<<<<<<<
 *     property tid:
 *         def __get__(self): return self.reference_id
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5qname_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5qname_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3571);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_name, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignmentfile.pyx":3573
 *         def __set__(self, v): self.query_name = v
 *     property tid:
 *         def __get__(self): return self.reference_id             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.reference_id = v
 *     property pos:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3tid_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3tid___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3tid___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3573);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":3574
 *     property tid:
 *         def __get__(self): return self.reference_id
 *         def __set__(self, v): self.reference_id = v             # <<<<<<<<<<<<<<
 *     property pos:
 *         def __get__(self): return self.reference_start
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3tid_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3tid_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3574);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignmentfile.pyx":3576
 *         def __set__(self, v): self.reference_id = v
 *     property pos:
 *         def __get__(self): return self.reference_start             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.reference_start = v
 *     property mapq:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3pos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3pos___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3pos___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3576);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":3577
 *     property pos:
 *         def __get__(self): return self.reference_start
 *         def __set__(self, v): self.reference_start = v             # <<<<<<<<<<<<<<
 *     property mapq:
 *         def __get__(self): return self.mapping_quality
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3pos_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3pos_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3577);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_start, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3577; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignmentfile.pyx":3579
 *         def __set__(self, v): self.reference_start = v
 *     property mapq:
 *         def __get__(self): return self.mapping_quality             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.mapping_quality = v
 *     property rnext:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mapq_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mapq_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mapq___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mapq___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3579);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":3580
 *     property mapq:
 *         def __get__(self): return self.mapping_quality
 *         def __set__(self, v): self.mapping_quality = v             # <<<<<<<<<<<<<<
 *     property rnext:
 *         def __get__(self): return self.next_reference_id
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mapq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mapq_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mapq_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3580);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignmentfile.pyx":3582
 *         def __set__(self, v): self.mapping_quality = v
 *     property rnext:
 *         def __get__(self): return self.next_reference_id             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.next_reference_id = v
 *     property pnext:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rnext_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rnext_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rnext___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rnext___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3582);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":3583
 *     property rnext:
 *         def __get__(self): return self.next_reference_id
 *         def __set__(self, v): self.next_reference_id = v             # <<<<<<<<<<<<<<
 *     property pnext:
 *         def __get__(self):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rnext_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rnext_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3583);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3583; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignmentfile.pyx":3585
 *         def __set__(self, v): self.next_reference_id = v
 *     property pnext:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_start
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5pnext_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5pnext_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5pnext___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":3586
 *     property pnext:
 *         def __get__(self):
 *             return self.next_reference_start             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.next_reference_start = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3585
 *         def __set__(self, v): self.next_reference_id = v
 *     property pnext:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_start
 *         def __set__(self, v):
 */

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

/* "pysam/calignmentfile.pyx":3587
 *         def __get__(self):
 *             return self.next_reference_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_start = v
 *     property cigar:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5pnext_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5pnext_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5pnext_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3587);

  /* "pysam/calignmentfile.pyx":3588
 *             return self.next_reference_start
 *         def __set__(self, v):
 *             self.next_reference_start = v             # <<<<<<<<<<<<<<
 *     property cigar:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3588; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3587
 *         def __get__(self):
 *             return self.next_reference_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_start = v
 *     property cigar:
 */

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

/* "pysam/calignmentfile.pyx":3590
 *             self.next_reference_start = v
 *     property cigar:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             r = self.cigartuples
 *             if r is None:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5cigar_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5cigar_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5cigar___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":3591
 *     property cigar:
 *         def __get__(self):
 *             r = self.cigartuples             # <<<<<<<<<<<<<<
 *             if r is None:
 *                 r = []
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3591; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_r = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":3592
 *         def __get__(self):
 *             r = self.cigartuples
 *             if r is None:             # <<<<<<<<<<<<<<
 *                 r = []
 *             return r
 */
  __pyx_t_2 = (__pyx_v_r == Py_None);
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (__pyx_t_3) {

    /* "pysam/calignmentfile.pyx":3593
 *             r = self.cigartuples
 *             if r is None:
 *                 r = []             # <<<<<<<<<<<<<<
 *             return r
 *         def __set__(self, v): self.cigartuples = v
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_r, __pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":3594
 *             if r is None:
 *                 r = []
 *             return r             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.cigartuples = v
 *     property tlen:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_r);
  __pyx_r = __pyx_v_r;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3590
 *             self.next_reference_start = v
 *     property cigar:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             r = self.cigartuples
 *             if r is None:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.cigar.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_r);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3595
 *                 r = []
 *             return r
 *         def __set__(self, v): self.cigartuples = v             # <<<<<<<<<<<<<<
 *     property tlen:
 *         def __get__(self):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5cigar_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5cigar_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5cigar_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3595);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_cigartuples, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3595; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignmentfile.pyx":3597
 *         def __set__(self, v): self.cigartuples = v
 *     property tlen:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.template_length
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tlen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tlen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4tlen___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":3598
 *     property tlen:
 *         def __get__(self):
 *             return self.template_length             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.template_length = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3598; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3597
 *         def __set__(self, v): self.cigartuples = v
 *     property tlen:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.template_length
 *         def __set__(self, v):
 */

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

/* "pysam/calignmentfile.pyx":3599
 *         def __get__(self):
 *             return self.template_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.template_length = v
 *     property seq:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4tlen_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4tlen_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3599);

  /* "pysam/calignmentfile.pyx":3600
 *             return self.template_length
 *         def __set__(self, v):
 *             self.template_length = v             # <<<<<<<<<<<<<<
 *     property seq:
 *         def __get__(self): return self.query_sequence
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3599
 *         def __get__(self):
 *             return self.template_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.template_length = v
 *     property seq:
 */

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

/* "pysam/calignmentfile.pyx":3602
 *             self.template_length = v
 *     property seq:
 *         def __get__(self): return self.query_sequence             # <<<<<<<<<<<<<<
 *         def __set__(self, v): self.query_sequence = v
 *     property qual:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3seq_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3seq_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3seq___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3seq___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3602);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3602; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

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

/* "pysam/calignmentfile.pyx":3603
 *     property seq:
 *         def __get__(self): return self.query_sequence
 *         def __set__(self, v): self.query_sequence = v             # <<<<<<<<<<<<<<
 *     property qual:
 *         def __get__(self):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3seq_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3seq_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_3seq_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3603);
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_sequence, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3603; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

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

/* "pysam/calignmentfile.pyx":3605
 *         def __set__(self, v): self.query_sequence = v
 *     property qual:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return toQualityString(self.query_qualities)
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qual_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qual_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qual___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":3606
 *     property qual:
 *         def __get__(self):
 *             return toQualityString(self.query_qualities)             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_qualities = fromQualityString(v)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_toQualityString); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3605
 *         def __set__(self, v): self.query_sequence = v
 *     property qual:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return toQualityString(self.query_qualities)
 *         def __set__(self, v):
 */

  /* 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_AddTraceback("pysam.calignmentfile.AlignedSegment.qual.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3607
 *         def __get__(self):
 *             return toQualityString(self.query_qualities)
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_qualities = fromQualityString(v)
 *     property alen:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qual_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qual_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3607);

  /* "pysam/calignmentfile.pyx":3608
 *             return toQualityString(self.query_qualities)
 *         def __set__(self, v):
 *             self.query_qualities = fromQualityString(v)             # <<<<<<<<<<<<<<
 *     property alen:
 *         def __get__(self):
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_fromQualityString); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_v); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
    __Pyx_INCREF(__pyx_v_v);
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_v);
    __Pyx_GIVEREF(__pyx_v_v);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_qualities, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3608; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":3607
 *         def __get__(self):
 *             return toQualityString(self.query_qualities)
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_qualities = fromQualityString(v)
 *     property alen:
 */

  /* 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.calignmentfile.AlignedSegment.qual.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3610
 *             self.query_qualities = fromQualityString(v)
 *     property alen:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_length
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4alen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4alen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4alen___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":3611
 *     property alen:
 *         def __get__(self):
 *             return self.reference_length             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.reference_length = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3610
 *             self.query_qualities = fromQualityString(v)
 *     property alen:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_length
 *         def __set__(self, v):
 */

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

/* "pysam/calignmentfile.pyx":3612
 *         def __get__(self):
 *             return self.reference_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_length = v
 *     property aend:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4alen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4alen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4alen_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4alen_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3612);

  /* "pysam/calignmentfile.pyx":3613
 *             return self.reference_length
 *         def __set__(self, v):
 *             self.reference_length = v             # <<<<<<<<<<<<<<
 *     property aend:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_length, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3613; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3612
 *         def __get__(self):
 *             return self.reference_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_length = v
 *     property aend:
 */

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

/* "pysam/calignmentfile.pyx":3615
 *             self.reference_length = v
 *     property aend:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_end
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4aend_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4aend_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4aend___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":3616
 *     property aend:
 *         def __get__(self):
 *             return self.reference_end             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.reference_end = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3616; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3615
 *             self.reference_length = v
 *     property aend:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_end
 *         def __set__(self, v):
 */

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

/* "pysam/calignmentfile.pyx":3617
 *         def __get__(self):
 *             return self.reference_end
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_end = v
 *     property rlen:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4aend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4aend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4aend_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4aend_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3617);

  /* "pysam/calignmentfile.pyx":3618
 *             return self.reference_end
 *         def __set__(self, v):
 *             self.reference_end = v             # <<<<<<<<<<<<<<
 *     property rlen:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_end, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3618; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3617
 *         def __get__(self):
 *             return self.reference_end
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_end = v
 *     property rlen:
 */

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

/* "pysam/calignmentfile.pyx":3620
 *             self.reference_end = v
 *     property rlen:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_length
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4rlen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4rlen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4rlen___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":3621
 *     property rlen:
 *         def __get__(self):
 *             return self.query_length             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_length = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3621; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3620
 *             self.reference_end = v
 *     property rlen:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_length
 *         def __set__(self, v):
 */

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

/* "pysam/calignmentfile.pyx":3622
 *         def __get__(self):
 *             return self.query_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_length = v
 *     property query:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4rlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4rlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4rlen_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4rlen_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3622);

  /* "pysam/calignmentfile.pyx":3623
 *             return self.query_length
 *         def __set__(self, v):
 *             self.query_length = v             # <<<<<<<<<<<<<<
 *     property query:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_length, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3623; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3622
 *         def __get__(self):
 *             return self.query_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_length = v
 *     property query:
 */

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

/* "pysam/calignmentfile.pyx":3625
 *             self.query_length = v
 *     property query:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_sequence
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5query_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5query_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5query___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":3626
 *     property query:
 *         def __get__(self):
 *             return self.query_alignment_sequence             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_alignment_sequence = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_sequence); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3625
 *             self.query_length = v
 *     property query:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_sequence
 *         def __set__(self, v):
 */

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

/* "pysam/calignmentfile.pyx":3627
 *         def __get__(self):
 *             return self.query_alignment_sequence
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_sequence = v
 *     property qqual:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5query_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5query_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5query_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5query_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3627);

  /* "pysam/calignmentfile.pyx":3628
 *             return self.query_alignment_sequence
 *         def __set__(self, v):
 *             self.query_alignment_sequence = v             # <<<<<<<<<<<<<<
 *     property qqual:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_sequence, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3627
 *         def __get__(self):
 *             return self.query_alignment_sequence
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_sequence = v
 *     property qqual:
 */

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

/* "pysam/calignmentfile.pyx":3630
 *             self.query_alignment_sequence = v
 *     property qqual:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return toQualityString(self.query_alignment_qualities)
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qqual_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qqual_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5qqual___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":3631
 *     property qqual:
 *         def __get__(self):
 *             return toQualityString(self.query_alignment_qualities)             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_alignment_qualities = fromQualityString(v)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_toQualityString); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_qualities); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); __pyx_t_4 = NULL;
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3630
 *             self.query_alignment_sequence = v
 *     property qqual:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return toQualityString(self.query_alignment_qualities)
 *         def __set__(self, v):
 */

  /* 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_AddTraceback("pysam.calignmentfile.AlignedSegment.qqual.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3632
 *         def __get__(self):
 *             return toQualityString(self.query_alignment_qualities)
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_qualities = fromQualityString(v)
 *     property qstart:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qqual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qqual_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5qqual_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5qqual_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3632);

  /* "pysam/calignmentfile.pyx":3633
 *             return toQualityString(self.query_alignment_qualities)
 *         def __set__(self, v):
 *             self.query_alignment_qualities = fromQualityString(v)             # <<<<<<<<<<<<<<
 *     property qstart:
 *         def __get__(self):
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_fromQualityString); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_v); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
    __Pyx_INCREF(__pyx_v_v);
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_v);
    __Pyx_GIVEREF(__pyx_v_v);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_qualities, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":3632
 *         def __get__(self):
 *             return toQualityString(self.query_alignment_qualities)
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_qualities = fromQualityString(v)
 *     property qstart:
 */

  /* 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.calignmentfile.AlignedSegment.qqual.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3635
 *             self.query_alignment_qualities = fromQualityString(v)
 *     property qstart:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_start
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_6qstart_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_6qstart_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_6qstart___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":3636
 *     property qstart:
 *         def __get__(self):
 *             return self.query_alignment_start             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_alignment_start = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3635
 *             self.query_alignment_qualities = fromQualityString(v)
 *     property qstart:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_start
 *         def __set__(self, v):
 */

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

/* "pysam/calignmentfile.pyx":3637
 *         def __get__(self):
 *             return self.query_alignment_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_start = v
 *     property qend:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_6qstart_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_6qstart_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_6qstart_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_6qstart_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3637);

  /* "pysam/calignmentfile.pyx":3638
 *             return self.query_alignment_start
 *         def __set__(self, v):
 *             self.query_alignment_start = v             # <<<<<<<<<<<<<<
 *     property qend:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_start, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3637
 *         def __get__(self):
 *             return self.query_alignment_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_start = v
 *     property qend:
 */

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

/* "pysam/calignmentfile.pyx":3640
 *             self.query_alignment_start = v
 *     property qend:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_end
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qend_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qend_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qend___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

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

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

  /* "pysam/calignmentfile.pyx":3641
 *     property qend:
 *         def __get__(self):
 *             return self.query_alignment_end             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_alignment_end = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_end); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3641; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3640
 *             self.query_alignment_start = v
 *     property qend:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_end
 *         def __set__(self, v):
 */

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

/* "pysam/calignmentfile.pyx":3642
 *         def __get__(self):
 *             return self.query_alignment_end
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_end = v
 *     property qlen:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qend_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qend_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

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

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qend_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3642);

  /* "pysam/calignmentfile.pyx":3643
 *             return self.query_alignment_end
 *         def __set__(self, v):
 *             self.query_alignment_end = v             # <<<<<<<<<<<<<<
 *     property qlen:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_end, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3643; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3642
 *         def __get__(self):
 *             return self.query_alignment_end
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_end = v
 *     property qlen:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.qend.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3645
 *             self.query_alignment_end = v
 *     property qlen:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_length
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qlen_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qlen_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qlen___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qlen___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3645);

  /* "pysam/calignmentfile.pyx":3646
 *     property qlen:
 *         def __get__(self):
 *             return self.query_alignment_length             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.query_alignment_length = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3646; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3645
 *             self.query_alignment_end = v
 *     property qlen:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.query_alignment_length
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.qlen.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3647
 *         def __get__(self):
 *             return self.query_alignment_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_length = v
 *     property mrnm:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qlen_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qlen_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4qlen_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3647);

  /* "pysam/calignmentfile.pyx":3648
 *             return self.query_alignment_length
 *         def __set__(self, v):
 *             self.query_alignment_length = v             # <<<<<<<<<<<<<<
 *     property mrnm:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_alignment_length, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3647
 *         def __get__(self):
 *             return self.query_alignment_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.query_alignment_length = v
 *     property mrnm:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.qlen.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3650
 *             self.query_alignment_length = v
 *     property mrnm:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_id
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mrnm_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mrnm_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mrnm___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mrnm___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3650);

  /* "pysam/calignmentfile.pyx":3651
 *     property mrnm:
 *         def __get__(self):
 *             return self.next_reference_id             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.next_reference_id = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3651; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3650
 *             self.query_alignment_length = v
 *     property mrnm:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_id
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.mrnm.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3652
 *         def __get__(self):
 *             return self.next_reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_id = v
 *     property mpos:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mrnm_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mrnm_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mrnm_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3652);

  /* "pysam/calignmentfile.pyx":3653
 *             return self.next_reference_id
 *         def __set__(self, v):
 *             self.next_reference_id = v             # <<<<<<<<<<<<<<
 *     property mpos:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_id, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3653; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3652
 *         def __get__(self):
 *             return self.next_reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_id = v
 *     property mpos:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.mrnm.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3655
 *             self.next_reference_id = v
 *     property mpos:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_start
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mpos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mpos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mpos___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mpos___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3655);

  /* "pysam/calignmentfile.pyx":3656
 *     property mpos:
 *         def __get__(self):
 *             return self.next_reference_start             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.next_reference_start = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3655
 *             self.next_reference_id = v
 *     property mpos:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.next_reference_start
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.mpos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3657
 *         def __get__(self):
 *             return self.next_reference_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_start = v
 *     property rname:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mpos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mpos_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4mpos_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3657);

  /* "pysam/calignmentfile.pyx":3658
 *             return self.next_reference_start
 *         def __set__(self, v):
 *             self.next_reference_start = v             # <<<<<<<<<<<<<<
 *     property rname:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_next_reference_start, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3658; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3657
 *         def __get__(self):
 *             return self.next_reference_start
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.next_reference_start = v
 *     property rname:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.mpos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3660
 *             self.next_reference_start = v
 *     property rname:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_id
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rname_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rname_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rname___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rname___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3660);

  /* "pysam/calignmentfile.pyx":3661
 *     property rname:
 *         def __get__(self):
 *             return self.reference_id             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.reference_id = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3660
 *             self.next_reference_start = v
 *     property rname:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_id
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.rname.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3662
 *         def __get__(self):
 *             return self.reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_id = v
 *     property isize:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rname_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rname_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5rname_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3662);

  /* "pysam/calignmentfile.pyx":3663
 *             return self.reference_id
 *         def __set__(self, v):
 *             self.reference_id = v             # <<<<<<<<<<<<<<
 *     property isize:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3662
 *         def __get__(self):
 *             return self.reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_id = v
 *     property isize:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.rname.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3665
 *             self.reference_id = v
 *     property isize:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.template_length
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5isize_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5isize_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5isize___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5isize___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3665);

  /* "pysam/calignmentfile.pyx":3666
 *     property isize:
 *         def __get__(self):
 *             return self.template_length             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.template_length = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3665
 *             self.reference_id = v
 *     property isize:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.template_length
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.isize.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3667
 *         def __get__(self):
 *             return self.template_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.template_length = v
 *     property blocks:
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5isize_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5isize_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_v));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_5isize_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3667);

  /* "pysam/calignmentfile.pyx":3668
 *             return self.template_length
 *         def __set__(self, v):
 *             self.template_length = v             # <<<<<<<<<<<<<<
 *     property blocks:
 *         def __get__(self):
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_template_length, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3667
 *         def __get__(self):
 *             return self.template_length
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.template_length = v
 *     property blocks:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.isize.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3670
 *             self.template_length = v
 *     property blocks:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_blocks()
 *     property aligned_pairs:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_6blocks_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_6blocks_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_6blocks___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_6blocks___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3670);

  /* "pysam/calignmentfile.pyx":3671
 *     property blocks:
 *         def __get__(self):
 *             return self.get_blocks()             # <<<<<<<<<<<<<<
 *     property aligned_pairs:
 *         def __get__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_blocks); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3671; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3670
 *             self.template_length = v
 *     property blocks:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_blocks()
 *     property aligned_pairs:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.blocks.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3673
 *             return self.get_blocks()
 *     property aligned_pairs:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_aligned_pairs()
 *     property inferred_length:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_13aligned_pairs_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_13aligned_pairs_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_13aligned_pairs___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_13aligned_pairs___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3673);

  /* "pysam/calignmentfile.pyx":3674
 *     property aligned_pairs:
 *         def __get__(self):
 *             return self.get_aligned_pairs()             # <<<<<<<<<<<<<<
 *     property inferred_length:
 *         def __get__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_aligned_pairs); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3673
 *             return self.get_blocks()
 *     property aligned_pairs:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_aligned_pairs()
 *     property inferred_length:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.aligned_pairs.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3676
 *             return self.get_aligned_pairs()
 *     property inferred_length:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.infer_query_length()
 *     property positions:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15inferred_length_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15inferred_length_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15inferred_length___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_15inferred_length___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3676);

  /* "pysam/calignmentfile.pyx":3677
 *     property inferred_length:
 *         def __get__(self):
 *             return self.infer_query_length()             # <<<<<<<<<<<<<<
 *     property positions:
 *         def __get__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_infer_query_length); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3676
 *             return self.get_aligned_pairs()
 *     property inferred_length:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.infer_query_length()
 *     property positions:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.inferred_length.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3679
 *             return self.infer_query_length()
 *     property positions:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_reference_positions()
 *     property tags:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9positions_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9positions_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9positions___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_9positions___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3679);

  /* "pysam/calignmentfile.pyx":3680
 *     property positions:
 *         def __get__(self):
 *             return self.get_reference_positions()             # <<<<<<<<<<<<<<
 *     property tags:
 *         def __get__(self):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_reference_positions); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3679
 *             return self.infer_query_length()
 *     property positions:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_reference_positions()
 *     property tags:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.positions.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3682
 *             return self.get_reference_positions()
 *     property tags:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_tags()
 *         def __set__(self, tags):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tags_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tags_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4tags___get__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4tags___get__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3682);

  /* "pysam/calignmentfile.pyx":3683
 *     property tags:
 *         def __get__(self):
 *             return self.get_tags()             # <<<<<<<<<<<<<<
 *         def __set__(self, tags):
 *             self.set_tags(tags)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_tags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3682
 *             return self.get_reference_positions()
 *     property tags:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.get_tags()
 *         def __set__(self, tags):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.tags.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3684
 *         def __get__(self):
 *             return self.get_tags()
 *         def __set__(self, tags):             # <<<<<<<<<<<<<<
 *             self.set_tags(tags)
 *     def overlap(self):
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tags_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_tags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4tags_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tags));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_4tags_2__set__(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3684);

  /* "pysam/calignmentfile.pyx":3685
 *             return self.get_tags()
 *         def __set__(self, tags):
 *             self.set_tags(tags)             # <<<<<<<<<<<<<<
 *     def overlap(self):
 *         return self.get_overlap()
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_set_tags); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_tags); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = NULL;
    __Pyx_INCREF(__pyx_v_tags);
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_tags);
    __Pyx_GIVEREF(__pyx_v_tags);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":3684
 *         def __get__(self):
 *             return self.get_tags()
 *         def __set__(self, tags):             # <<<<<<<<<<<<<<
 *             self.set_tags(tags)
 *     def overlap(self):
 */

  /* 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.calignmentfile.AlignedSegment.tags.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3686
 *         def __set__(self, tags):
 *             self.set_tags(tags)
 *     def overlap(self):             # <<<<<<<<<<<<<<
 *         return self.get_overlap()
 *     def opt(self, tag):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_33overlap(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_32overlap[] = "AlignedSegment.overlap(self)";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_33overlap(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("overlap (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_32overlap(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_32overlap(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("overlap", 0);
  __Pyx_TraceCall("overlap", __pyx_f[0], 3686);

  /* "pysam/calignmentfile.pyx":3687
 *             self.set_tags(tags)
 *     def overlap(self):
 *         return self.get_overlap()             # <<<<<<<<<<<<<<
 *     def opt(self, tag):
 *         return self.get_tag(tag)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get_overlap); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3686
 *         def __set__(self, tags):
 *             self.set_tags(tags)
 *     def overlap(self):             # <<<<<<<<<<<<<<
 *         return self.get_overlap()
 *     def opt(self, tag):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.overlap", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3688
 *     def overlap(self):
 *         return self.get_overlap()
 *     def opt(self, tag):             # <<<<<<<<<<<<<<
 *         return self.get_tag(tag)
 *     def setTag(self, tag, value, value_type=None, replace=True):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_35opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_34opt[] = "AlignedSegment.opt(self, tag)";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_35opt(PyObject *__pyx_v_self, PyObject *__pyx_v_tag) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("opt (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_34opt(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), ((PyObject *)__pyx_v_tag));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_34opt(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("opt", 0);
  __Pyx_TraceCall("opt", __pyx_f[0], 3688);

  /* "pysam/calignmentfile.pyx":3689
 *         return self.get_overlap()
 *     def opt(self, tag):
 *         return self.get_tag(tag)             # <<<<<<<<<<<<<<
 *     def setTag(self, tag, value, value_type=None, replace=True):
 *         return self.set_tag(tag, value, value_type, replace)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self->__pyx_vtab)->get_tag(__pyx_v_self, __pyx_v_tag, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3688
 *     def overlap(self):
 *         return self.get_overlap()
 *     def opt(self, tag):             # <<<<<<<<<<<<<<
 *         return self.get_tag(tag)
 *     def setTag(self, tag, value, value_type=None, replace=True):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.opt", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3690
 *     def opt(self, tag):
 *         return self.get_tag(tag)
 *     def setTag(self, tag, value, value_type=None, replace=True):             # <<<<<<<<<<<<<<
 *         return self.set_tag(tag, value, value_type, replace)
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_37setTag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_36setTag[] = "AlignedSegment.setTag(self, tag, value, value_type=None, replace=True)";
static PyObject *__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_37setTag(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tag = 0;
  PyObject *__pyx_v_value = 0;
  PyObject *__pyx_v_value_type = 0;
  PyObject *__pyx_v_replace = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("setTag (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tag,&__pyx_n_s_value,&__pyx_n_s_value_type,&__pyx_n_s_replace,0};
    PyObject* values[4] = {0,0,0,0};
    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);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tag)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("setTag", 0, 2, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3690; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value_type);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_replace);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "setTag") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3690; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_tag = values[0];
    __pyx_v_value = values[1];
    __pyx_v_value_type = values[2];
    __pyx_v_replace = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("setTag", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3690; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.setTag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_14AlignedSegment_36setTag(((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self), __pyx_v_tag, __pyx_v_value, __pyx_v_value_type, __pyx_v_replace);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_14AlignedSegment_36setTag(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *__pyx_v_self, PyObject *__pyx_v_tag, PyObject *__pyx_v_value, PyObject *__pyx_v_value_type, PyObject *__pyx_v_replace) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_5pysam_14calignmentfile_14AlignedSegment_set_tag __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("setTag", 0);
  __Pyx_TraceCall("setTag", __pyx_f[0], 3690);

  /* "pysam/calignmentfile.pyx":3691
 *         return self.get_tag(tag)
 *     def setTag(self, tag, value, value_type=None, replace=True):
 *         return self.set_tag(tag, value, value_type, replace)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 2;
  __pyx_t_2.value_type = __pyx_v_value_type;
  __pyx_t_2.replace = __pyx_v_replace;
  __pyx_t_1 = ((struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignedSegment *)__pyx_v_self->__pyx_vtab)->set_tag(__pyx_v_self, __pyx_v_tag, __pyx_v_value, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3690
 *     def opt(self, tag):
 *         return self.get_tag(tag)
 *     def setTag(self, tag, value, value_type=None, replace=True):             # <<<<<<<<<<<<<<
 *         return self.set_tag(tag, value, value_type, replace)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.AlignedSegment.setTag", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3704
 * 
 *     '''
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError("this class cannot be instantiated from Python")
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_12PileupColumn_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_12PileupColumn_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn___init__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_12PileupColumn___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 3704);

  /* "pysam/calignmentfile.pyx":3705
 *     '''
 *     def __init__(self):
 *         raise TypeError("this class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__81, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3704
 * 
 *     '''
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError("this class cannot be instantiated from Python")
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3707
 *         raise TypeError("this class cannot be instantiated from Python")
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join(map(str,
 *                               (self.reference_id,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_3__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_3__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_2__str__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_2__str__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 3707);

  /* "pysam/calignmentfile.pyx":3708
 * 
 *     def __str__(self):
 *         return "\t".join(map(str,             # <<<<<<<<<<<<<<
 *                               (self.reference_id,
 *                                self.reference_pos,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/calignmentfile.pyx":3709
 *     def __str__(self):
 *         return "\t".join(map(str,
 *                               (self.reference_id,             # <<<<<<<<<<<<<<
 *                                self.reference_pos,
 *                                self.nsegments))) +\
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/calignmentfile.pyx":3710
 *         return "\t".join(map(str,
 *                               (self.reference_id,
 *                                self.reference_pos,             # <<<<<<<<<<<<<<
 *                                self.nsegments))) +\
 *             "\n" +\
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/calignmentfile.pyx":3711
 *                               (self.reference_id,
 *                                self.reference_pos,
 *                                self.nsegments))) +\             # <<<<<<<<<<<<<<
 *             "\n" +\
 *             "\n".join(map(str, self.pileups))
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/calignmentfile.pyx":3709
 *     def __str__(self):
 *         return "\t".join(map(str,
 *                               (self.reference_id,             # <<<<<<<<<<<<<<
 *                                self.reference_pos,
 *                                self.nsegments))) +\
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;

  /* "pysam/calignmentfile.pyx":3708
 * 
 *     def __str__(self):
 *         return "\t".join(map(str,             # <<<<<<<<<<<<<<
 *                               (self.reference_id,
 *                                self.reference_pos,
 */
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyString_Join(__pyx_kp_s__46, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysam/calignmentfile.pyx":3711
 *                               (self.reference_id,
 *                                self.reference_pos,
 *                                self.nsegments))) +\             # <<<<<<<<<<<<<<
 *             "\n" +\
 *             "\n".join(map(str, self.pileups))
 */
  __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_kp_s__41); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/calignmentfile.pyx":3713
 *                                self.nsegments))) +\
 *             "\n" +\
 *             "\n".join(map(str, self.pileups))             # <<<<<<<<<<<<<<
 * 
 *     property reference_id:
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_pileups); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__41, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "pysam/calignmentfile.pyx":3712
 *                                self.reference_pos,
 *                                self.nsegments))) +\
 *             "\n" +\             # <<<<<<<<<<<<<<
 *             "\n".join(map(str, self.pileups))
 * 
 */
  __pyx_t_3 = PyNumber_Add(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3712; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3707
 *         raise TypeError("this class cannot be instantiated from Python")
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join(map(str,
 *                               (self.reference_id,
 */

  /* 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.calignmentfile.PileupColumn.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3717
 *     property reference_id:
 *         '''the reference sequence number as defined in the header'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.tid
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_12reference_id_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_12reference_id_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_12reference_id___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_12reference_id___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3717);

  /* "pysam/calignmentfile.pyx":3718
 *         '''the reference sequence number as defined in the header'''
 *         def __get__(self):
 *             return self.tid             # <<<<<<<<<<<<<<
 * 
 *     property nsegments:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3717
 *     property reference_id:
 *         '''the reference sequence number as defined in the header'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.tid
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.reference_id.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3722
 *     property nsegments:
 *         '''number of reads mapping to this column.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.n_pu
 *         def __set__(self, n):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_9nsegments_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_9nsegments_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_9nsegments___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_9nsegments___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3722);

  /* "pysam/calignmentfile.pyx":3723
 *         '''number of reads mapping to this column.'''
 *         def __get__(self):
 *             return self.n_pu             # <<<<<<<<<<<<<<
 *         def __set__(self, n):
 *             self.n_pu = n
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->n_pu); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3722
 *     property nsegments:
 *         '''number of reads mapping to this column.'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.n_pu
 *         def __set__(self, n):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.nsegments.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3724
 *         def __get__(self):
 *             return self.n_pu
 *         def __set__(self, n):             # <<<<<<<<<<<<<<
 *             self.n_pu = n
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_12PileupColumn_9nsegments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_12PileupColumn_9nsegments_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_n) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_9nsegments_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_n));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_12PileupColumn_9nsegments_2__set__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self, PyObject *__pyx_v_n) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3724);

  /* "pysam/calignmentfile.pyx":3725
 *             return self.n_pu
 *         def __set__(self, n):
 *             self.n_pu = n             # <<<<<<<<<<<<<<
 * 
 *     property reference_pos:
 */
  __pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_n); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_self->n_pu = __pyx_t_1;

  /* "pysam/calignmentfile.pyx":3724
 *         def __get__(self):
 *             return self.n_pu
 *         def __set__(self, n):             # <<<<<<<<<<<<<<
 *             self.n_pu = n
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.nsegments.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3729
 *     property reference_pos:
 *         '''the position in the reference sequence (0-based).'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.pos
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_13reference_pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_13reference_pos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_13reference_pos___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_13reference_pos___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3729);

  /* "pysam/calignmentfile.pyx":3730
 *         '''the position in the reference sequence (0-based).'''
 *         def __get__(self):
 *             return self.pos             # <<<<<<<<<<<<<<
 * 
 *     property pileups:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3730; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3729
 *     property reference_pos:
 *         '''the position in the reference sequence (0-based).'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.pos
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.reference_pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3734
 *     property pileups:
 *         '''list of reads (:class:`pysam.PileupRead`) aligned to this column'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef int x
 *             pileups = []
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_7pileups_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_7pileups_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_7pileups___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_7pileups___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self) {
  int __pyx_v_x;
  PyObject *__pyx_v_pileups = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3734);

  /* "pysam/calignmentfile.pyx":3736
 *         def __get__(self):
 *             cdef int x
 *             pileups = []             # <<<<<<<<<<<<<<
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_pileups = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":3738
 *             pileups = []
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:             # <<<<<<<<<<<<<<
 *                 raise ValueError("PileupColumn accessed after iterator finished")
 * 
 */
  __pyx_t_3 = ((__pyx_v_self->plp == NULL) != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (((__pyx_v_self->plp[0]) == NULL) != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":3739
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:
 *                 raise ValueError("PileupColumn accessed after iterator finished")             # <<<<<<<<<<<<<<
 * 
 *             # warning: there could be problems if self.n and self.buf are
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__82, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":3743
 *             # warning: there could be problems if self.n and self.buf are
 *             # out of sync.
 *             for x from 0 <= x < self.n_pu:             # <<<<<<<<<<<<<<
 *                 pileups.append(makePileupRead(&(self.plp[0][x])))
 *             return pileups
 */
  __pyx_t_4 = __pyx_v_self->n_pu;
  for (__pyx_v_x = 0; __pyx_v_x < __pyx_t_4; __pyx_v_x++) {

    /* "pysam/calignmentfile.pyx":3744
 *             # out of sync.
 *             for x from 0 <= x < self.n_pu:
 *                 pileups.append(makePileupRead(&(self.plp[0][x])))             # <<<<<<<<<<<<<<
 *             return pileups
 * 
 */
    __pyx_t_1 = __pyx_f_5pysam_14calignmentfile_makePileupRead((&((__pyx_v_self->plp[0])[__pyx_v_x]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyList_Append(__pyx_v_pileups, __pyx_t_1); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "pysam/calignmentfile.pyx":3745
 *             for x from 0 <= x < self.n_pu:
 *                 pileups.append(makePileupRead(&(self.plp[0][x])))
 *             return pileups             # <<<<<<<<<<<<<<
 * 
 *     ########################################################
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_pileups);
  __pyx_r = __pyx_v_pileups;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3734
 *     property pileups:
 *         '''list of reads (:class:`pysam.PileupRead`) aligned to this column'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             cdef int x
 *             pileups = []
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.pileups.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_pileups);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3752
 *     ########################################################
 *     property pos:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_pos
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_3pos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_3pos___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_3pos___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3752);

  /* "pysam/calignmentfile.pyx":3753
 *     property pos:
 *         def __get__(self):
 *             return self.reference_pos             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.reference_pos = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3752
 *     ########################################################
 *     property pos:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_pos
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3754
 *         def __get__(self):
 *             return self.reference_pos
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_pos = v
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_12PileupColumn_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_12PileupColumn_3pos_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_3pos_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_12PileupColumn_3pos_2__set__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3754);

  /* "pysam/calignmentfile.pyx":3755
 *             return self.reference_pos
 *         def __set__(self, v):
 *             self.reference_pos = v             # <<<<<<<<<<<<<<
 * 
 *     property tid:
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_pos, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3755; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3754
 *         def __get__(self):
 *             return self.reference_pos
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_pos = v
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.pos.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3758
 * 
 *     property tid:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_id
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_3tid_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_3tid___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_3tid___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3758);

  /* "pysam/calignmentfile.pyx":3759
 *     property tid:
 *         def __get__(self):
 *             return self.reference_id             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.reference_id = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3759; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3758
 * 
 *     property tid:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.reference_id
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3760
 *         def __get__(self):
 *             return self.reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_id = v
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_12PileupColumn_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_12PileupColumn_3tid_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_3tid_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_12PileupColumn_3tid_2__set__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3760);

  /* "pysam/calignmentfile.pyx":3761
 *             return self.reference_id
 *         def __set__(self, v):
 *             self.reference_id = v             # <<<<<<<<<<<<<<
 * 
 *     property n:
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_id, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3761; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3760
 *         def __get__(self):
 *             return self.reference_id
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.reference_id = v
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.tid.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3764
 * 
 *     property n:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.nsegments
 *         def __set__(self, v):
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_1n_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_12PileupColumn_1n_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_1n___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_12PileupColumn_1n___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3764);

  /* "pysam/calignmentfile.pyx":3765
 *     property n:
 *         def __get__(self):
 *             return self.nsegments             # <<<<<<<<<<<<<<
 *         def __set__(self, v):
 *             self.nsegments = v
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3764
 * 
 *     property n:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self.nsegments
 *         def __set__(self, v):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.n.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3766
 *         def __get__(self):
 *             return self.nsegments
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.nsegments = v
 * 
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_12PileupColumn_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_12PileupColumn_1n_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__set__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12PileupColumn_1n_2__set__(((struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *)__pyx_v_self), ((PyObject *)__pyx_v_v));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_12PileupColumn_1n_2__set__(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn *__pyx_v_self, PyObject *__pyx_v_v) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__set__", 0);
  __Pyx_TraceCall("__set__", __pyx_f[0], 3766);

  /* "pysam/calignmentfile.pyx":3767
 *             return self.nsegments
 *         def __set__(self, v):
 *             self.nsegments = v             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_nsegments, __pyx_v_v) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3766
 *         def __get__(self):
 *             return self.nsegments
 *         def __set__(self, v):             # <<<<<<<<<<<<<<
 *             self.nsegments = v
 * 
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.PileupColumn.n.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3776
 *     '''
 * 
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError(
 *             "this class cannot be instantiated from Python")
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_10PileupRead_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
    __Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
  if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_10PileupRead___init__(((struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static int __pyx_pf_5pysam_14calignmentfile_10PileupRead___init__(CYTHON_UNUSED struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 3776);

  /* "pysam/calignmentfile.pyx":3777
 * 
 *     def __init__(self):
 *         raise TypeError(             # <<<<<<<<<<<<<<
 *             "this class cannot be instantiated from Python")
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__83, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":3776
 *     '''
 * 
 *     def __init__(self):             # <<<<<<<<<<<<<<
 *         raise TypeError(
 *             "this class cannot be instantiated from Python")
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupRead.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3780
 *             "this class cannot be instantiated from Python")
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 *         return "\t".join(
 *             map(str,
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_3__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_3__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_10PileupRead_2__str__(((struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_2__str__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 3780);

  /* "pysam/calignmentfile.pyx":3781
 * 
 *     def __str__(self):
 *         return "\t".join(             # <<<<<<<<<<<<<<
 *             map(str,
 *                 (self.alignment, self.query_position,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/calignmentfile.pyx":3783
 *         return "\t".join(
 *             map(str,
 *                 (self.alignment, self.query_position,             # <<<<<<<<<<<<<<
 *                  self.indel, self.level,
 *                  self.is_del, self.is_head,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_alignment); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_query_position); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/calignmentfile.pyx":3784
 *             map(str,
 *                 (self.alignment, self.query_position,
 *                  self.indel, self.level,             # <<<<<<<<<<<<<<
 *                  self.is_del, self.is_head,
 *                  self.is_tail, self.is_refskip)))
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_indel); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_level); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3784; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/calignmentfile.pyx":3785
 *                 (self.alignment, self.query_position,
 *                  self.indel, self.level,
 *                  self.is_del, self.is_head,             # <<<<<<<<<<<<<<
 *                  self.is_tail, self.is_refskip)))
 * 
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_del); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_head); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3785; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);

  /* "pysam/calignmentfile.pyx":3786
 *                  self.indel, self.level,
 *                  self.is_del, self.is_head,
 *                  self.is_tail, self.is_refskip)))             # <<<<<<<<<<<<<<
 * 
 *     property alignment:
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_tail); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_refskip); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);

  /* "pysam/calignmentfile.pyx":3783
 *         return "\t".join(
 *             map(str,
 *                 (self.alignment, self.query_position,             # <<<<<<<<<<<<<<
 *                  self.indel, self.level,
 *                  self.is_del, self.is_head,
 */
  __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 7, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;

  /* "pysam/calignmentfile.pyx":3782
 *     def __str__(self):
 *         return "\t".join(
 *             map(str,             # <<<<<<<<<<<<<<
 *                 (self.alignment, self.query_position,
 *                  self.indel, self.level,
 */
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3782; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "pysam/calignmentfile.pyx":3781
 * 
 *     def __str__(self):
 *         return "\t".join(             # <<<<<<<<<<<<<<
 *             map(str,
 *                 (self.alignment, self.query_position,
 */
  __pyx_t_8 = __Pyx_PyString_Join(__pyx_kp_s__46, __pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_r = __pyx_t_8;
  __pyx_t_8 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3780
 *             "this class cannot be instantiated from Python")
 * 
 *     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.calignmentfile.PileupRead.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3790
 *     property alignment:
 *         """a :class:`pysam.AlignedSegment` object of the aligned read"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._alignment
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_9alignment_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_10PileupRead_9alignment___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_9alignment___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3790);

  /* "pysam/calignmentfile.pyx":3791
 *         """a :class:`pysam.AlignedSegment` object of the aligned read"""
 *         def __get__(self):
 *             return self._alignment             # <<<<<<<<<<<<<<
 * 
 *     property query_position:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_self->_alignment));
  __pyx_r = ((PyObject *)__pyx_v_self->_alignment);
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3790
 *     property alignment:
 *         """a :class:`pysam.AlignedSegment` object of the aligned read"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._alignment
 * 
 */

  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3798
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.is_del or self.is_refskip:
 *                 return None
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_14query_position_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_14query_position_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_10PileupRead_14query_position___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_14query_position___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3798);

  /* "pysam/calignmentfile.pyx":3799
 *         """
 *         def __get__(self):
 *             if self.is_del or self.is_refskip:             # <<<<<<<<<<<<<<
 *                 return None
 *             else:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_del); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3799; __pyx_clineno = __LINE__; goto __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_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_is_refskip); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":3800
 *         def __get__(self):
 *             if self.is_del or self.is_refskip:
 *                 return None             # <<<<<<<<<<<<<<
 *             else:
 *                 return self._qpos
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":3802
 *                 return None
 *             else:
 *                 return self._qpos             # <<<<<<<<<<<<<<
 * 
 *     property indel:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = __Pyx_PyInt_From_int32_t(__pyx_v_self->_qpos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3802; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;
  }

  /* "pysam/calignmentfile.pyx":3798
 * 
 *         """
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             if self.is_del or self.is_refskip:
 *                 return None
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupRead.query_position.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3806
 *     property indel:
 *         """indel length; 0 for no indel, positive for ins and negative            for del"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._indel
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_5indel_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_10PileupRead_5indel___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_5indel___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3806);

  /* "pysam/calignmentfile.pyx":3807
 *         """indel length; 0 for no indel, positive for ins and negative            for del"""
 *         def __get__(self):
 *             return self._indel             # <<<<<<<<<<<<<<
 * 
 *     property level:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_indel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3807; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3806
 *     property indel:
 *         """indel length; 0 for no indel, positive for ins and negative            for del"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._indel
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupRead.indel.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3811
 *     property level:
 *         """the level of the read in the "viewer" mode"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._level
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_5level_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_5level_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_10PileupRead_5level___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_5level___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3811);

  /* "pysam/calignmentfile.pyx":3812
 *         """the level of the read in the "viewer" mode"""
 *         def __get__(self):
 *             return self._level             # <<<<<<<<<<<<<<
 * 
 *     property is_del:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_level); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3811
 *     property level:
 *         """the level of the read in the "viewer" mode"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._level
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupRead.level.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3816
 *     property is_del:
 *         """1 iff the base on the padded read is a deletion"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_del
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_6is_del_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_10PileupRead_6is_del___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_6is_del___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3816);

  /* "pysam/calignmentfile.pyx":3817
 *         """1 iff the base on the padded read is a deletion"""
 *         def __get__(self):
 *             return self._is_del             # <<<<<<<<<<<<<<
 * 
 *     property is_head:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_del); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3817; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3816
 *     property is_del:
 *         """1 iff the base on the padded read is a deletion"""
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_del
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupRead.is_del.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3820
 * 
 *     property is_head:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_head
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_7is_head_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_10PileupRead_7is_head___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_7is_head___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3820);

  /* "pysam/calignmentfile.pyx":3821
 *     property is_head:
 *         def __get__(self):
 *             return self._is_head             # <<<<<<<<<<<<<<
 * 
 *     property is_tail:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_head); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3820
 * 
 *     property is_head:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_head
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupRead.is_head.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3824
 * 
 *     property is_tail:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_tail
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_7is_tail_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_10PileupRead_7is_tail___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_7is_tail___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3824);

  /* "pysam/calignmentfile.pyx":3825
 *     property is_tail:
 *         def __get__(self):
 *             return self._is_tail             # <<<<<<<<<<<<<<
 * 
 *     property is_refskip:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_tail); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3825; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3824
 * 
 *     property is_tail:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_tail
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupRead.is_tail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3828
 * 
 *     property is_refskip:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_refskip
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_10is_refskip_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_10PileupRead_10is_refskip_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_10PileupRead_10is_refskip___get__(((struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_10PileupRead_10is_refskip___get__(struct __pyx_obj_5pysam_14calignmentfile_PileupRead *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3828);

  /* "pysam/calignmentfile.pyx":3829
 *     property is_refskip:
 *         def __get__(self):
 *             return self._is_refskip             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_uint32_t(__pyx_v_self->_is_refskip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3828
 * 
 *     property is_refskip:
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._is_refskip
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.PileupRead.is_refskip.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3845
 *     property tid:
 *         '''the chromosome ID as is defined in the header'''
 *         def __get__(self):             # <<<<<<<<<<<<<<
 *             return self._tid
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_7SNPCall_3tid_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_7SNPCall_3tid_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_7SNPCall_3tid___get__(((struct __pyx_obj_5pysam_14calignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_3tid___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3845);

  /* "pysam/calignmentfile.pyx":3846
 *         '''the chromosome ID as is defined in the header'''
 *         def __get__(self):
 *             return self._tid             # <<<<<<<<<<<<<<
 * 
 *     property pos:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3845
 *     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.calignmentfile.SNPCall.tid.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3850
 *     property pos:
 *        '''nucleotide position of SNP.'''
 *        def __get__(self): return self._pos             # <<<<<<<<<<<<<<
 * 
 *     property reference_base:
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_7SNPCall_3pos_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_7SNPCall_3pos_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_7SNPCall_3pos___get__(((struct __pyx_obj_5pysam_14calignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_3pos___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3850);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3850; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.SNPCall.pos.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3854
 *     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_14calignmentfile_7SNPCall_14reference_base_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_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_14calignmentfile_7SNPCall_14reference_base___get__(((struct __pyx_obj_5pysam_14calignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_14reference_base___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3854);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile_from_string_and_size((&__pyx_v_self->_reference_base), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.SNPCall.reference_base.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3858
 *     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_14calignmentfile_7SNPCall_8genotype_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_7SNPCall_8genotype_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_7SNPCall_8genotype___get__(((struct __pyx_obj_5pysam_14calignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_8genotype___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3858);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile_from_string_and_size((&__pyx_v_self->_genotype), 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.SNPCall.genotype.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3862
 *     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_14calignmentfile_7SNPCall_17consensus_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_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_14calignmentfile_7SNPCall_17consensus_quality___get__(((struct __pyx_obj_5pysam_14calignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_17consensus_quality___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3862);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_consensus_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.SNPCall.consensus_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3867
 *        '''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_14calignmentfile_7SNPCall_11snp_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_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_14calignmentfile_7SNPCall_11snp_quality___get__(((struct __pyx_obj_5pysam_14calignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_11snp_quality___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3867);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_snp_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.SNPCall.snp_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3872
 *        '''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_14calignmentfile_7SNPCall_15mapping_quality_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_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_14calignmentfile_7SNPCall_15mapping_quality___get__(((struct __pyx_obj_5pysam_14calignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_15mapping_quality___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3872);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_rms_mapping_quality); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.SNPCall.mapping_quality.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3876
 *     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_14calignmentfile_7SNPCall_8coverage_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_7SNPCall_8coverage_1__get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_7SNPCall_8coverage___get__(((struct __pyx_obj_5pysam_14calignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall_8coverage___get__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__get__", 0);
  __Pyx_TraceCall("__get__", __pyx_f[0], 3876);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_coverage); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.SNPCall.coverage.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3878
 *        def __get__(self): return self._coverage
 * 
 *     def __str__(self):             # <<<<<<<<<<<<<<
 * 
 *         return "\t".join( map(str, (
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_7SNPCall_1__str__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_5pysam_14calignmentfile_7SNPCall_1__str__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_7SNPCall___str__(((struct __pyx_obj_5pysam_14calignmentfile_SNPCall *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_7SNPCall___str__(struct __pyx_obj_5pysam_14calignmentfile_SNPCall *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__str__", 0);
  __Pyx_TraceCall("__str__", __pyx_f[0], 3878);

  /* "pysam/calignmentfile.pyx":3880
 *     def __str__(self):
 * 
 *         return "\t".join( map(str, (             # <<<<<<<<<<<<<<
 *                     self.tid,
 *                     self.pos,
 */
  __Pyx_XDECREF(__pyx_r);

  /* "pysam/calignmentfile.pyx":3881
 * 
 *         return "\t".join( map(str, (
 *                     self.tid,             # <<<<<<<<<<<<<<
 *                     self.pos,
 *                     self.reference_base,
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_tid); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);

  /* "pysam/calignmentfile.pyx":3882
 *         return "\t".join( map(str, (
 *                     self.tid,
 *                     self.pos,             # <<<<<<<<<<<<<<
 *                     self.reference_base,
 *                     self.genotype,
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_pos); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);

  /* "pysam/calignmentfile.pyx":3883
 *                     self.tid,
 *                     self.pos,
 *                     self.reference_base,             # <<<<<<<<<<<<<<
 *                     self.genotype,
 *                     self.consensus_quality,
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reference_base); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);

  /* "pysam/calignmentfile.pyx":3884
 *                     self.pos,
 *                     self.reference_base,
 *                     self.genotype,             # <<<<<<<<<<<<<<
 *                     self.consensus_quality,
 *                     self.snp_quality,
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_genotype); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);

  /* "pysam/calignmentfile.pyx":3885
 *                     self.reference_base,
 *                     self.genotype,
 *                     self.consensus_quality,             # <<<<<<<<<<<<<<
 *                     self.snp_quality,
 *                     self.mapping_quality,
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_consensus_quality); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);

  /* "pysam/calignmentfile.pyx":3886
 *                     self.genotype,
 *                     self.consensus_quality,
 *                     self.snp_quality,             # <<<<<<<<<<<<<<
 *                     self.mapping_quality,
 *                     self.coverage ) ) )
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_snp_quality); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);

  /* "pysam/calignmentfile.pyx":3887
 *                     self.consensus_quality,
 *                     self.snp_quality,
 *                     self.mapping_quality,             # <<<<<<<<<<<<<<
 *                     self.coverage ) ) )
 * 
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_mapping_quality); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);

  /* "pysam/calignmentfile.pyx":3888
 *                     self.snp_quality,
 *                     self.mapping_quality,
 *                     self.coverage ) ) )             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_coverage); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);

  /* "pysam/calignmentfile.pyx":3881
 * 
 *         return "\t".join( map(str, (
 *                     self.tid,             # <<<<<<<<<<<<<<
 *                     self.pos,
 *                     self.reference_base,
 */
  __pyx_t_9 = PyTuple_New(8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_9, 3, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_9, 4, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_9, 5, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_9, 6, __pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_9, 7, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_8);
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_8 = 0;

  /* "pysam/calignmentfile.pyx":3880
 *     def __str__(self):
 * 
 *         return "\t".join( map(str, (             # <<<<<<<<<<<<<<
 *                     self.tid,
 *                     self.pos,
 */
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_INCREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_8, 0, ((PyObject *)((PyObject*)(&PyString_Type))));
  __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyString_Type))));
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyString_Join(__pyx_kp_s__46, __pyx_t_9); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __pyx_r = __pyx_t_8;
  __pyx_t_8 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3878
 *        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.calignmentfile.SNPCall.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3901
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=True):             # <<<<<<<<<<<<<<
 * 
 *         # makes sure that samfile stays alive as long as this
 */

/* Python wrapper */
static int __pyx_pw_5pysam_14calignmentfile_12IndexedReads_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_5pysam_14calignmentfile_12IndexedReads_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_14calignmentfile_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);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_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_filename = __pyx_f[0]; __pyx_lineno = 3901; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_14calignmentfile_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_filename = __pyx_f[0]; __pyx_lineno = 3901; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 3901; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.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_14calignmentfile_AlignmentFile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3901; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_12IndexedReads___init__(((struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_12IndexedReads___init__(struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *__pyx_v_self, struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *__pyx_v_samfile, int __pyx_v_multiple_iterators) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  char const *__pyx_t_2;
  htsFile *__pyx_t_3;
  bam_hdr_t *__pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__init__", 0);
  __Pyx_TraceCall("__init__", __pyx_f[0], 3901);

  /* "pysam/calignmentfile.pyx":3905
 *         # makes sure that samfile stays alive as long as this
 *         # object is alive.
 *         self.samfile = samfile             # <<<<<<<<<<<<<<
 * 
 *         assert samfile.is_bam, "can only IndexReads on bam files"
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_samfile));
  __Pyx_GOTREF(__pyx_v_self->samfile);
  __Pyx_DECREF(((PyObject *)__pyx_v_self->samfile));
  __pyx_v_self->samfile = __pyx_v_samfile;

  /* "pysam/calignmentfile.pyx":3907
 *         self.samfile = samfile
 * 
 *         assert samfile.is_bam, "can only IndexReads on bam files"             # <<<<<<<<<<<<<<
 * 
 *         # multiple_iterators the file - note that this makes the iterator
 */
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    if (unlikely(!(__pyx_v_samfile->is_bam != 0))) {
      PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_can_only_IndexReads_on_bam_files);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif

  /* "pysam/calignmentfile.pyx":3911
 *         # multiple_iterators the file - note that this makes the iterator
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:             # <<<<<<<<<<<<<<
 *             self.htsfile = hts_open(samfile._filename, 'r')
 *             assert self.htsfile != NULL
 */
  __pyx_t_1 = (__pyx_v_multiple_iterators != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":3912
 *         # slow and causes pileup to slow down significantly.
 *         if multiple_iterators:
 *             self.htsfile = hts_open(samfile._filename, 'r')             # <<<<<<<<<<<<<<
 *             assert self.htsfile != NULL
 *             # read header - required for accurate positioning
 */
    __pyx_t_2 = __Pyx_PyObject_AsString(__pyx_v_samfile->_filename); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_self->htsfile = hts_open(__pyx_t_2, __pyx_k_r);

    /* "pysam/calignmentfile.pyx":3913
 *         if multiple_iterators:
 *             self.htsfile = hts_open(samfile._filename, 'r')
 *             assert self.htsfile != NULL             # <<<<<<<<<<<<<<
 *             # read header - required for accurate positioning
 *             self.header = sam_hdr_read(self.htsfile)
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      if (unlikely(!((__pyx_v_self->htsfile != NULL) != 0))) {
        PyErr_SetNone(PyExc_AssertionError);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3913; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
    }
    #endif

    /* "pysam/calignmentfile.pyx":3915
 *             assert self.htsfile != NULL
 *             # read header - required for accurate positioning
 *             self.header = sam_hdr_read(self.htsfile)             # <<<<<<<<<<<<<<
 *             self.owns_samfile = True
 *         else:
 */
    __pyx_v_self->header = sam_hdr_read(__pyx_v_self->htsfile);

    /* "pysam/calignmentfile.pyx":3916
 *             # read header - required for accurate positioning
 *             self.header = sam_hdr_read(self.htsfile)
 *             self.owns_samfile = True             # <<<<<<<<<<<<<<
 *         else:
 *             self.htsfile = self.samfile.htsfile
 */
    __pyx_v_self->owns_samfile = 1;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":3918
 *             self.owns_samfile = True
 *         else:
 *             self.htsfile = self.samfile.htsfile             # <<<<<<<<<<<<<<
 *             self.header = self.samfile.header
 *             self.owns_samfile = False
 */
    __pyx_t_3 = __pyx_v_self->samfile->htsfile;
    __pyx_v_self->htsfile = __pyx_t_3;

    /* "pysam/calignmentfile.pyx":3919
 *         else:
 *             self.htsfile = self.samfile.htsfile
 *             self.header = self.samfile.header             # <<<<<<<<<<<<<<
 *             self.owns_samfile = False
 * 
 */
    __pyx_t_4 = __pyx_v_self->samfile->header;
    __pyx_v_self->header = __pyx_t_4;

    /* "pysam/calignmentfile.pyx":3920
 *             self.htsfile = self.samfile.htsfile
 *             self.header = self.samfile.header
 *             self.owns_samfile = False             # <<<<<<<<<<<<<<
 * 
 *     def build(self):
 */
    __pyx_v_self->owns_samfile = 0;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":3901
 *     """
 * 
 *     def __init__(self, AlignmentFile samfile, int multiple_iterators=True):             # <<<<<<<<<<<<<<
 * 
 *         # makes sure that samfile stays alive as long as this
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.IndexedReads.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3922
 *             self.owns_samfile = False
 * 
 *     def build(self):             # <<<<<<<<<<<<<<
 *         '''build index.'''
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_12IndexedReads_3build(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_12IndexedReads_2build[] = "IndexedReads.build(self)\nbuild index.";
static PyObject *__pyx_pw_5pysam_14calignmentfile_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_14calignmentfile_12IndexedReads_2build(((struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_12IndexedReads_2build(struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *__pyx_v_self) {
  int __pyx_v_ret;
  bam1_t *__pyx_v_b;
  uint64_t __pyx_v_pos;
  PyObject *__pyx_v_qname = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("build", 0);
  __Pyx_TraceCall("build", __pyx_f[0], 3922);

  /* "pysam/calignmentfile.pyx":3925
 *         '''build index.'''
 * 
 *         self.index = collections.defaultdict(list)             # <<<<<<<<<<<<<<
 * 
 *         # this method will start indexing from the current file
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_collections); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3925; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 3925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (!__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, ((PyObject *)((PyObject*)(&PyList_Type)))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = NULL;
    __Pyx_INCREF(((PyObject *)((PyObject*)(&PyList_Type))));
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)((PyObject*)(&PyList_Type))));
    __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyList_Type))));
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __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/calignmentfile.pyx":3929
 *         # this method will start indexing from the current file
 *         # position if you decide
 *         cdef int ret = 1             # <<<<<<<<<<<<<<
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))
 * 
 */
  __pyx_v_ret = 1;

  /* "pysam/calignmentfile.pyx":3930
 *         # position if you decide
 *         cdef int ret = 1
 *         cdef bam1_t * b = <bam1_t*>calloc(1, sizeof( bam1_t))             # <<<<<<<<<<<<<<
 * 
 *         cdef uint64_t pos
 */
  __pyx_v_b = ((bam1_t *)calloc(1, (sizeof(bam1_t))));

  /* "pysam/calignmentfile.pyx":3934
 *         cdef uint64_t pos
 * 
 *         while ret > 0:             # <<<<<<<<<<<<<<
 *             pos = bgzf_tell(hts_get_bgzfp(self.htsfile))
 *             ret = sam_read1(self.htsfile,
 */
  while (1) {
    __pyx_t_5 = ((__pyx_v_ret > 0) != 0);
    if (!__pyx_t_5) break;

    /* "pysam/calignmentfile.pyx":3935
 * 
 *         while ret > 0:
 *             pos = bgzf_tell(hts_get_bgzfp(self.htsfile))             # <<<<<<<<<<<<<<
 *             ret = sam_read1(self.htsfile,
 *                             self.samfile.header,
 */
    __pyx_v_pos = bgzf_tell(hts_get_bgzfp(__pyx_v_self->htsfile));

    /* "pysam/calignmentfile.pyx":3936
 *         while ret > 0:
 *             pos = bgzf_tell(hts_get_bgzfp(self.htsfile))
 *             ret = sam_read1(self.htsfile,             # <<<<<<<<<<<<<<
 *                             self.samfile.header,
 *                             b)
 */
    __pyx_v_ret = sam_read1(__pyx_v_self->htsfile, __pyx_v_self->samfile->header, __pyx_v_b);

    /* "pysam/calignmentfile.pyx":3939
 *                             self.samfile.header,
 *                             b)
 *             if ret > 0:             # <<<<<<<<<<<<<<
 *                 qname = _charptr_to_str(pysam_bam_get_qname(b))
 *                 self.index[qname].append(pos)
 */
    __pyx_t_5 = ((__pyx_v_ret > 0) != 0);
    if (__pyx_t_5) {

      /* "pysam/calignmentfile.pyx":3940
 *                             b)
 *             if ret > 0:
 *                 qname = _charptr_to_str(pysam_bam_get_qname(b))             # <<<<<<<<<<<<<<
 *                 self.index[qname].append(pos)
 * 
 */
      __pyx_t_1 = __pyx_f_5pysam_14calignmentfile__charptr_to_str(pysam_bam_get_qname(__pyx_v_b)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_v_qname, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "pysam/calignmentfile.pyx":3941
 *             if ret > 0:
 *                 qname = _charptr_to_str(pysam_bam_get_qname(b))
 *                 self.index[qname].append(pos)             # <<<<<<<<<<<<<<
 * 
 *         bam_destroy1(b)
 */
      __pyx_t_1 = PyObject_GetItem(__pyx_v_self->index, __pyx_v_qname); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3941; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyInt_From_uint64_t(__pyx_v_pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_t_3); if (unlikely(__pyx_t_6 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  /* "pysam/calignmentfile.pyx":3943
 *                 self.index[qname].append(pos)
 * 
 *         bam_destroy1(b)             # <<<<<<<<<<<<<<
 * 
 *     def find(self, query_name):
 */
  bam_destroy1(__pyx_v_b);

  /* "pysam/calignmentfile.pyx":3922
 *             self.owns_samfile = False
 * 
 *     def build(self):             # <<<<<<<<<<<<<<
 *         '''build index.'''
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysam.calignmentfile.IndexedReads.build", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_qname);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3945
 *         bam_destroy1(b)
 * 
 *     def find(self, query_name):             # <<<<<<<<<<<<<<
 *         '''find *query_name* in index.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_12IndexedReads_5find(PyObject *__pyx_v_self, PyObject *__pyx_v_query_name); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_12IndexedReads_4find[] = "IndexedReads.find(self, query_name)\nfind *query_name* in index.\n\n        Returns an iterator over all reads with query_name.\n\n        Raise a KeyError if the *query_name* is not in the index.\n        ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_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_14calignmentfile_12IndexedReads_4find(((struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *)__pyx_v_self), ((PyObject *)__pyx_v_query_name));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_12IndexedReads_4find(struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *__pyx_v_self, PyObject *__pyx_v_query_name) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("find", 0);
  __Pyx_TraceCall("find", __pyx_f[0], 3945);

  /* "pysam/calignmentfile.pyx":3952
 *         Raise a KeyError if the *query_name* is not in the index.
 *         '''
 *         if query_name in self.index:             # <<<<<<<<<<<<<<
 *             return IteratorRowSelection(
 *                 self.samfile,
 */
  __pyx_t_1 = (__Pyx_PySequence_Contains(__pyx_v_query_name, __pyx_v_self->index, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "pysam/calignmentfile.pyx":3953
 *         '''
 *         if query_name in self.index:
 *             return IteratorRowSelection(             # <<<<<<<<<<<<<<
 *                 self.samfile,
 *                 self.index[query_name],
 */
    __Pyx_XDECREF(__pyx_r);

    /* "pysam/calignmentfile.pyx":3955
 *             return IteratorRowSelection(
 *                 self.samfile,
 *                 self.index[query_name],             # <<<<<<<<<<<<<<
 *                 multiple_iterators = False)
 *         else:
 */
    __pyx_t_3 = PyObject_GetItem(__pyx_v_self->index, __pyx_v_query_name); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3955; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/calignmentfile.pyx":3953
 *         '''
 *         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_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(((PyObject *)__pyx_v_self->samfile));
    PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_self->samfile));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self->samfile));
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);

    /* "pysam/calignmentfile.pyx":3956
 *                 self.samfile,
 *                 self.index[query_name],
 *                 multiple_iterators = False)             # <<<<<<<<<<<<<<
 *         else:
 *             raise KeyError("read %s not found" % query_name)
 */
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_multiple_iterators, Py_False) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysam/calignmentfile.pyx":3953
 *         '''
 *         if query_name in self.index:
 *             return IteratorRowSelection(             # <<<<<<<<<<<<<<
 *                 self.samfile,
 *                 self.index[query_name],
 */
    __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5pysam_14calignmentfile_IteratorRowSelection)), __pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_5;
    __pyx_t_5 = 0;
    goto __pyx_L0;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":3958
 *                 multiple_iterators = False)
 *         else:
 *             raise KeyError("read %s not found" % query_name)             # <<<<<<<<<<<<<<
 * 
 *     def __dealloc__(self):
 */
    __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_read_s_not_found, __pyx_v_query_name); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_Raise(__pyx_t_5, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3958; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "pysam/calignmentfile.pyx":3945
 *         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.calignmentfile.IndexedReads.find", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3960
 *             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_14calignmentfile_12IndexedReads_7__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_5pysam_14calignmentfile_12IndexedReads_7__dealloc__(PyObject *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
  __pyx_pf_5pysam_14calignmentfile_12IndexedReads_6__dealloc__(((struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
}

static void __pyx_pf_5pysam_14calignmentfile_12IndexedReads_6__dealloc__(struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *__pyx_v_self) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__dealloc__", 0);
  __Pyx_TraceCall("__dealloc__", __pyx_f[0], 3960);

  /* "pysam/calignmentfile.pyx":3961
 * 
 *     def __dealloc__(self):
 *         if self.owns_samfile:             # <<<<<<<<<<<<<<
 *             hts_close(self.htsfile)
 *             bam_hdr_destroy(self.header)
 */
  __pyx_t_1 = (__pyx_v_self->owns_samfile != 0);
  if (__pyx_t_1) {

    /* "pysam/calignmentfile.pyx":3962
 *     def __dealloc__(self):
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)             # <<<<<<<<<<<<<<
 *             bam_hdr_destroy(self.header)
 * 
 */
    hts_close(__pyx_v_self->htsfile);

    /* "pysam/calignmentfile.pyx":3963
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 *             bam_hdr_destroy(self.header)             # <<<<<<<<<<<<<<
 * 
 * cpdef set_verbosity(int verbosity):
 */
    bam_hdr_destroy(__pyx_v_self->header);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":3960
 *             raise KeyError("read %s not found" % query_name)
 * 
 *     def __dealloc__(self):             # <<<<<<<<<<<<<<
 *         if self.owns_samfile:
 *             hts_close(self.htsfile)
 */

  /* function exit code */
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "pysam/calignmentfile.pyx":3965
 *             bam_hdr_destroy(self.header)
 * 
 * cpdef set_verbosity(int verbosity):             # <<<<<<<<<<<<<<
 *     u"""Set htslib's hts_verbose global variable to the specified value.
 *     """
 */

static PyObject *__pyx_pw_5pysam_14calignmentfile_5set_verbosity(PyObject *__pyx_self, PyObject *__pyx_arg_verbosity); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_set_verbosity(int __pyx_v_verbosity, CYTHON_UNUSED int __pyx_skip_dispatch) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("set_verbosity", 0);
  __Pyx_TraceCall("set_verbosity", __pyx_f[0], 3965);

  /* "pysam/calignmentfile.pyx":3968
 *     u"""Set htslib's hts_verbose global variable to the specified value.
 *     """
 *     return hts_set_verbosity(verbosity)             # <<<<<<<<<<<<<<
 * 
 * cpdef get_verbosity():
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(hts_set_verbosity(__pyx_v_verbosity)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3968; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3965
 *             bam_hdr_destroy(self.header)
 * 
 * cpdef set_verbosity(int verbosity):             # <<<<<<<<<<<<<<
 *     u"""Set htslib's hts_verbose global variable to the specified value.
 *     """
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.set_verbosity", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_5set_verbosity(PyObject *__pyx_self, PyObject *__pyx_arg_verbosity); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_4set_verbosity[] = "set_verbosity(int verbosity)\nSet htslib's hts_verbose global variable to the specified value.\n    ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_5set_verbosity(PyObject *__pyx_self, PyObject *__pyx_arg_verbosity) {
  int __pyx_v_verbosity;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("set_verbosity (wrapper)", 0);
  assert(__pyx_arg_verbosity); {
    __pyx_v_verbosity = __Pyx_PyInt_As_int(__pyx_arg_verbosity); if (unlikely((__pyx_v_verbosity == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3965; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysam.calignmentfile.set_verbosity", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_4set_verbosity(__pyx_self, ((int)__pyx_v_verbosity));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_4set_verbosity(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_verbosity) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("set_verbosity", 0);
  __Pyx_TraceCall("set_verbosity", __pyx_f[0], 3965);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile_set_verbosity(__pyx_v_verbosity, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3965; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.set_verbosity", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysam/calignmentfile.pyx":3970
 *     return hts_set_verbosity(verbosity)
 * 
 * cpdef get_verbosity():             # <<<<<<<<<<<<<<
 *     u"""Return the value of htslib's hts_verbose global variable.
 *     """
 */

static PyObject *__pyx_pw_5pysam_14calignmentfile_7get_verbosity(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyObject *__pyx_f_5pysam_14calignmentfile_get_verbosity(CYTHON_UNUSED int __pyx_skip_dispatch) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("get_verbosity", 0);
  __Pyx_TraceCall("get_verbosity", __pyx_f[0], 3970);

  /* "pysam/calignmentfile.pyx":3973
 *     u"""Return the value of htslib's hts_verbose global variable.
 *     """
 *     return hts_get_verbosity()             # <<<<<<<<<<<<<<
 * 
 * __all__ = ["AlignmentFile",
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyInt_From_int(hts_get_verbosity()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3973; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "pysam/calignmentfile.pyx":3970
 *     return hts_set_verbosity(verbosity)
 * 
 * cpdef get_verbosity():             # <<<<<<<<<<<<<<
 *     u"""Return the value of htslib's hts_verbose global variable.
 *     """
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.get_verbosity", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_5pysam_14calignmentfile_7get_verbosity(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_5pysam_14calignmentfile_6get_verbosity[] = "get_verbosity()\nReturn the value of htslib's hts_verbose global variable.\n    ";
static PyObject *__pyx_pw_5pysam_14calignmentfile_7get_verbosity(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("get_verbosity (wrapper)", 0);
  __pyx_r = __pyx_pf_5pysam_14calignmentfile_6get_verbosity(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_5pysam_14calignmentfile_6get_verbosity(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("get_verbosity", 0);
  __Pyx_TraceCall("get_verbosity", __pyx_f[0], 3970);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_5pysam_14calignmentfile_get_verbosity(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3970; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysam.calignmentfile.get_verbosity", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_TraceReturn(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":91
 *             __data_union data
 * 
 *         def __getbuffer__(self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fullfill 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_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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  if (__pyx_v_info != NULL) {
    __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(__pyx_v_info->obj);
  }
  __Pyx_TraceCall("__getbuffer__", __pyx_f[2], 91);

  /* "array.pxd":96
 *             # 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_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_item_count = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "array.pxd":98
 *             item_count = Py_SIZE(self)
 * 
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *             info.buf = self.data.as_chars
 *             info.readonly = 0
 */
  __pyx_v_info->suboffsets = NULL;

  /* "array.pxd":99
 * 
 *             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":100
 *             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":101
 *             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":102
 *             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":103
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 *             info.len = info.itemsize * item_count             # <<<<<<<<<<<<<<
 * 
 *             info.shape = <Py_ssize_t*> PyMem_Malloc(sizeof(Py_ssize_t) + 2)
 */
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_info->itemsize); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_info->len = __pyx_t_5;

  /* "array.pxd":105
 *             info.len = info.itemsize * item_count
 * 
 *             info.shape = <Py_ssize_t*> PyMem_Malloc(sizeof(Py_ssize_t) + 2)             # <<<<<<<<<<<<<<
 *             if not info.shape:
 *                 raise MemoryError()
 */
  __pyx_v_info->shape = ((Py_ssize_t *)PyMem_Malloc(((sizeof(Py_ssize_t)) + 2)));

  /* "array.pxd":106
 * 
 *             info.shape = <Py_ssize_t*> PyMem_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 (__pyx_t_6) {

    /* "array.pxd":107
 *             info.shape = <Py_ssize_t*> PyMem_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_filename = __pyx_f[2]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "array.pxd":108
 *             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_filename = __pyx_f[2]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  (__pyx_v_info->shape[0]) = __pyx_t_5;

  /* "array.pxd":109
 *                 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":111
 *             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":112
 * 
 *             info.format = <char*> (info.shape + 1)
 *             info.format[0] = self.ob_descr.typecode             # <<<<<<<<<<<<<<
 *             info.format[1] = 0
 *             info.obj = self
 */
  __pyx_t_3 = __pyx_v_self->ob_descr->typecode;
  (__pyx_v_info->format[0]) = __pyx_t_3;

  /* "array.pxd":113
 *             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":114
 *             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":91
 *             __data_union data
 * 
 *         def __getbuffer__(self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fullfill 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 != NULL && __pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(Py_None);
    __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL;
  }
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_item_count);
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":116
 *             info.obj = self
 * 
 *         def __releasebuffer__(self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             PyMem_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_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("__releasebuffer__", 0);
  __Pyx_TraceCall("__releasebuffer__", __pyx_f[2], 116);

  /* "array.pxd":117
 * 
 *         def __releasebuffer__(self, Py_buffer* info):
 *             PyMem_Free(info.shape)             # <<<<<<<<<<<<<<
 * 
 *     array newarrayobject(PyTypeObject* type, Py_ssize_t size, arraydescr *descr)
 */
  PyMem_Free(__pyx_v_info->shape);

  /* "array.pxd":116
 *             info.obj = self
 * 
 *         def __releasebuffer__(self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             PyMem_Free(info.shape)
 * 
 */

  /* function exit code */
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}

/* "array.pxd":128
 * 
 * 
 * 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 = NULL;
  arrayobject *__pyx_r = NULL;
  __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_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("clone", 0);
  __Pyx_TraceCall("clone", __pyx_f[2], 128);

  /* "array.pxd":132
 *     type will be same as template.
 *     if zero is true, new array will be initialized with zeroes."""
 *     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_filename = __pyx_f[2]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_op = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "array.pxd":133
 *     if zero is true, new array will be initialized with zeroes."""
 *     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":134
 *     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
 * 
 */
    memset(__pyx_v_op->data.as_chars, 0, (__pyx_v_length * __pyx_v_op->ob_descr->itemsize));
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "array.pxd":135
 *     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":128
 * 
 * 
 * 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);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":137
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an 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 = NULL;
  arrayobject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("copy", 0);
  __Pyx_TraceCall("copy", __pyx_f[2], 137);

  /* "array.pxd":139
 * cdef inline array copy(array self):
 *     """ make a copy of an 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_filename = __pyx_f[2]; __pyx_lineno = 139; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_op = ((arrayobject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "array.pxd":140
 *     """ make a copy of an 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
 * 
 */
  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":141
 *     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":137
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an 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);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":143
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficent 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_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("extend_buffer", 0);
  __Pyx_TraceCall("extend_buffer", __pyx_f[2], 143);

  /* "array.pxd":147
 *     (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":148
 *     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":149
 *     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 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "array.pxd":150
 *     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
 * 
 */
  memcpy((__pyx_v_self->data.as_chars + (__pyx_v_origsize * __pyx_v_itemsize)), __pyx_v_stuff, (__pyx_v_n * __pyx_v_itemsize));

  /* "array.pxd":151
 *     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":143
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficent 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);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":153
 *     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_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("extend", 0);
  __Pyx_TraceCall("extend", __pyx_f[2], 153);

  /* "array.pxd":155
 * 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":156
 *     """ 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 == 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "array.pxd":157
 *     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 == -1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_t_2;
  goto __pyx_L0;

  /* "array.pxd":153
 *     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);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "array.pxd":159
 *     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_RefNannyDeclarations
  __Pyx_TraceDeclarations(NULL)
  __Pyx_RefNannySetupContext("zero", 0);
  __Pyx_TraceCall("zero", __pyx_f[2], 159);

  /* "array.pxd":161
 * 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)             # <<<<<<<<<<<<<<
 */
  memset(__pyx_v_self->data.as_chars, 0, (Py_SIZE(((PyObject *)__pyx_v_self)) * __pyx_v_self->ob_descr->itemsize));

  /* "array.pxd":159
 *     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 */
  __Pyx_TraceReturn(Py_None);
  __Pyx_RefNannyFinishContext();
}
static struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignedSegment __pyx_vtable_5pysam_14calignmentfile_AlignedSegment;

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_AlignedSegment(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *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_14calignmentfile_AlignedSegment *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_14calignmentfile_AlignedSegment;
  return o;
}

static void __pyx_tp_dealloc_5pysam_14calignmentfile_AlignedSegment(PyObject *o) {
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_name(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10query_name_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_query_name(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10query_name_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_flag(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4flag_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_flag(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4flag_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_reference_id(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12reference_id_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_reference_id(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12reference_id_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_reference_start(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15reference_start_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_reference_start(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15reference_start_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mapping_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mapping_quality_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mapping_quality(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mapping_quality_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_cigarstring(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigarstring_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_cigarstring(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigarstring_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_next_reference_id(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_next_reference_id(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_17next_reference_id_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_next_reference_start(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_20next_reference_start_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_next_reference_start(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_20next_reference_start_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12query_length_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_template_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15template_length_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_template_length(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15template_length_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_sequence(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14query_sequence_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_query_sequence(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14query_sequence_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_qualities(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15query_qualities_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_query_qualities(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15query_qualities_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_bin(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3bin_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_bin(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3bin_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_paired(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_paired_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_paired(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_paired_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_proper_pair(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14is_proper_pair_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_proper_pair(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_14is_proper_pair_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_unmapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11is_unmapped_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_unmapped(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11is_unmapped_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mate_is_unmapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16mate_is_unmapped_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mate_is_unmapped(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16mate_is_unmapped_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_reverse(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10is_reverse_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_reverse(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_10is_reverse_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mate_is_reverse(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mate_is_reverse_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mate_is_reverse(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15mate_is_reverse_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_read1(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read1_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_read1(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read1_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_read2(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read2_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_read2(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_8is_read2_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_secondary(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_secondary_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_secondary(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_secondary_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_qcfail(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_qcfail_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_qcfail(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9is_qcfail_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_duplicate(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_duplicate_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_duplicate(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_12is_duplicate_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_supplementary(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16is_supplementary_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_supplementary(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16is_supplementary_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_reference_end(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_13reference_end_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_reference_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_16reference_length_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_alignment_sequence(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_24query_alignment_sequence_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_alignment_qualities(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_25query_alignment_qualities_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_alignment_start(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_21query_alignment_start_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_alignment_end(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_19query_alignment_end_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_alignment_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_22query_alignment_length_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_cigartuples(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigartuples_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_cigartuples(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11cigartuples_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qname(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qname_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qname(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qname_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_tid(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3tid_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_tid(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3tid_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3pos_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_pos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3pos_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mapq(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mapq_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mapq(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mapq_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_rnext(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rnext_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_rnext(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rnext_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_pnext(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5pnext_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_pnext(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5pnext_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_cigar(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5cigar_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_cigar(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5cigar_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_tlen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tlen_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_tlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tlen_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_seq(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3seq_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_seq(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_3seq_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qual(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qual_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qual(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qual_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_alen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4alen_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_alen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4alen_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_aend(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4aend_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_aend(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4aend_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_rlen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4rlen_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_rlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4rlen_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5query_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_query(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5query_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qqual(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qqual_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qqual(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5qqual_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qstart(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_6qstart_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qstart(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_6qstart_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qend(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qend_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qend(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qend_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qlen(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qlen_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qlen(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4qlen_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mrnm(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mrnm_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mrnm(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mrnm_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mpos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mpos_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mpos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4mpos_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_rname(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rname_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_rname(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5rname_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_isize(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5isize_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_isize(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5isize_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_blocks(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_6blocks_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_aligned_pairs(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_13aligned_pairs_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_inferred_length(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15inferred_length_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_positions(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9positions_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_tags(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tags_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_tags(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_4tags_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_AlignedSegment[] = {
  {"compare", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_7compare, METH_O, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_6compare},
  {"get_reference_positions", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_13get_reference_positions, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_12get_reference_positions},
  {"infer_query_length", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_15infer_query_length, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_14infer_query_length},
  {"get_aligned_pairs", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_17get_aligned_pairs, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_16get_aligned_pairs},
  {"get_blocks", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_19get_blocks, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_18get_blocks},
  {"get_overlap", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_21get_overlap, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_20get_overlap},
  {"set_tag", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_23set_tag, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_22set_tag},
  {"has_tag", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_25has_tag, METH_O, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_24has_tag},
  {"get_tag", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_27get_tag, METH_O, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_26get_tag},
  {"get_tags", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_29get_tags, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_28get_tags},
  {"set_tags", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_31set_tags, METH_O, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_30set_tags},
  {"overlap", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_33overlap, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_32overlap},
  {"opt", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_35opt, METH_O, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_34opt},
  {"setTag", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14AlignedSegment_37setTag, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_36setTag},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_14calignmentfile_AlignedSegment[] = {
  {(char *)"query_name", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_name, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_query_name, __pyx_k_the_query_template_name_None_if, 0},
  {(char *)"flag", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_flag, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_flag, __pyx_k_properties_flag, 0},
  {(char *)"reference_id", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_reference_id, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_reference_id, __pyx_k_term_reference_ID_note_This_fie, 0},
  {(char *)"reference_start", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_reference_start, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_reference_start, __pyx_k_0_based_leftmost_coordinate, 0},
  {(char *)"mapping_quality", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mapping_quality, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mapping_quality, __pyx_k_mapping_quality_2, 0},
  {(char *)"cigarstring", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_cigarstring, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_cigarstring, __pyx_k_the_term_cigar_alignment_as_a_st, 0},
  {(char *)"next_reference_id", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_next_reference_id, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_next_reference_id, __pyx_k_the_term_reference_id_of_the_mat, 0},
  {(char *)"next_reference_start", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_next_reference_start, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_next_reference_start, __pyx_k_the_position_of_the_mate_next_re, 0},
  {(char *)"query_length", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_length, 0, __pyx_k_the_length_of_the_query_read_Thi, 0},
  {(char *)"template_length", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_template_length, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_template_length, __pyx_k_the_observed_query_template_leng, 0},
  {(char *)"query_sequence", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_sequence, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_query_sequence, __pyx_k_read_sequence_bases_including_te, 0},
  {(char *)"query_qualities", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_qualities, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_query_qualities, __pyx_k_read_sequence_base_qualities_inc, 0},
  {(char *)"bin", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_bin, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_bin, __pyx_k_properties_bin, 0},
  {(char *)"is_paired", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_paired, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_paired, __pyx_k_true_if_read_is_paired_in_sequen, 0},
  {(char *)"is_proper_pair", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_proper_pair, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_proper_pair, __pyx_k_true_if_read_is_mapped_in_a_prop, 0},
  {(char *)"is_unmapped", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_unmapped, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_unmapped, __pyx_k_true_if_read_itself_is_unmapped, 0},
  {(char *)"mate_is_unmapped", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mate_is_unmapped, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mate_is_unmapped, __pyx_k_true_if_the_mate_is_unmapped, 0},
  {(char *)"is_reverse", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_reverse, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_reverse, __pyx_k_true_if_read_is_mapped_to_revers, 0},
  {(char *)"mate_is_reverse", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mate_is_reverse, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mate_is_reverse, __pyx_k_true_is_read_is_mapped_to_revers, 0},
  {(char *)"is_read1", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_read1, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_read1, __pyx_k_true_if_this_is_read1, 0},
  {(char *)"is_read2", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_read2, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_read2, __pyx_k_true_if_this_is_read2, 0},
  {(char *)"is_secondary", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_secondary, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_secondary, __pyx_k_true_if_not_primary_alignment, 0},
  {(char *)"is_qcfail", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_qcfail, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_qcfail, __pyx_k_true_if_QC_failure, 0},
  {(char *)"is_duplicate", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_duplicate, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_duplicate, __pyx_k_true_if_optical_or_PCR_duplicate, 0},
  {(char *)"is_supplementary", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_is_supplementary, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_is_supplementary, __pyx_k_true_if_this_is_a_supplementary, 0},
  {(char *)"reference_end", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_reference_end, 0, __pyx_k_aligned_reference_position_of_th, 0},
  {(char *)"reference_length", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_reference_length, 0, __pyx_k_aligned_length_of_the_read_on_th, 0},
  {(char *)"query_alignment_sequence", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_alignment_sequence, 0, __pyx_k_aligned_portion_of_the_read_This, 0},
  {(char *)"query_alignment_qualities", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_alignment_qualities, 0, __pyx_k_aligned_query_sequence_quality_v, 0},
  {(char *)"query_alignment_start", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_alignment_start, 0, __pyx_k_start_index_of_the_aligned_query, 0},
  {(char *)"query_alignment_end", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_alignment_end, 0, __pyx_k_end_index_of_the_aligned_query_p, 0},
  {(char *)"query_alignment_length", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query_alignment_length, 0, __pyx_k_length_of_the_aligned_query_sequ, 0},
  {(char *)"cigartuples", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_cigartuples, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_cigartuples, __pyx_k_the_term_cigar_alignment_The_ali, 0},
  {(char *)"qname", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qname, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qname, 0, 0},
  {(char *)"tid", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_tid, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_tid, 0, 0},
  {(char *)"pos", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_pos, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_pos, 0, 0},
  {(char *)"mapq", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mapq, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mapq, 0, 0},
  {(char *)"rnext", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_rnext, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_rnext, 0, 0},
  {(char *)"pnext", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_pnext, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_pnext, 0, 0},
  {(char *)"cigar", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_cigar, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_cigar, 0, 0},
  {(char *)"tlen", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_tlen, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_tlen, 0, 0},
  {(char *)"seq", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_seq, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_seq, 0, 0},
  {(char *)"qual", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qual, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qual, 0, 0},
  {(char *)"alen", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_alen, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_alen, 0, 0},
  {(char *)"aend", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_aend, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_aend, 0, 0},
  {(char *)"rlen", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_rlen, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_rlen, 0, 0},
  {(char *)"query", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_query, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_query, 0, 0},
  {(char *)"qqual", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qqual, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qqual, 0, 0},
  {(char *)"qstart", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qstart, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qstart, 0, 0},
  {(char *)"qend", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qend, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qend, 0, 0},
  {(char *)"qlen", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_qlen, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_qlen, 0, 0},
  {(char *)"mrnm", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mrnm, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mrnm, 0, 0},
  {(char *)"mpos", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_mpos, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_mpos, 0, 0},
  {(char *)"rname", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_rname, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_rname, 0, 0},
  {(char *)"isize", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_isize, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_isize, 0, 0},
  {(char *)"blocks", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_blocks, 0, 0, 0},
  {(char *)"aligned_pairs", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_aligned_pairs, 0, 0, 0},
  {(char *)"inferred_length", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_inferred_length, 0, 0, 0},
  {(char *)"positions", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_positions, 0, 0, 0},
  {(char *)"tags", __pyx_getprop_5pysam_14calignmentfile_14AlignedSegment_tags, __pyx_setprop_5pysam_14calignmentfile_14AlignedSegment_tags, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_AlignedSegment = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.AlignedSegment", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_AlignedSegment, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_11__hash__, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_5__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "AlignedSegment()\nClass representing an aligned segment. \n\n    This class stores a handle to the samtools C-structure representing\n    an aligned read. Member read access is forwarded to the C-structure\n    and converted into python objects. This implementation should be fast,\n    as only the data needed is converted.\n\n    For write access, the C-structure is updated in-place. This is\n    not the most efficient way to build BAM entries, as the variable\n    length data is concatenated and thus needs to be resized if\n    a field is updated. Furthermore, the BAM entry might be\n    in an inconsistent state.\n\n    One issue to look out for is that the sequence should always\n    be set *before* the quality scores. Setting the sequence will\n    also erase any quality scores that were set previously.\n    ", /*tp_doc*/
  0, /*tp_traverse*/
  0, /*tp_clear*/
  __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_9__richcmp__, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_AlignedSegment, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_14calignmentfile_AlignedSegment, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5pysam_14calignmentfile_14AlignedSegment_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile_AlignedSegment, /*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
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_AlignmentFile __pyx_vtable_5pysam_14calignmentfile_AlignmentFile;

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_AlignmentFile(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *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_14calignmentfile_AlignmentFile *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_14calignmentfile_AlignmentFile;
  p->_filename = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_1__cinit__(o, a, k) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_14calignmentfile_AlignmentFile(PyObject *o) {
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *p = (struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_35__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->_filename);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_14calignmentfile_AlignmentFile(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *p = (struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)o;
  if (p->_filename) {
    e = (*v)(p->_filename, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_14calignmentfile_AlignmentFile(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *p = (struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)o;
  tmp = ((PyObject*)p->_filename);
  p->_filename = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_filename(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_8filename_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_nreferences(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_11nreferences_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_references(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_10references_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_lengths(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_7lengths_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_mapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_6mapped_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_unmapped(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_8unmapped_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_nocoordinate(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_12nocoordinate_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_text(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_4text_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_header(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_6header_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_is_bam(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_6is_bam_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_is_cram(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_7is_cram_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_is_stream(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_9is_stream_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_is_remote(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_9is_remote_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_AlignmentFile[] = {
  {"_isOpen", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_3_isOpen, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_2_isOpen},
  {"_hasIndex", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_5_hasIndex, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_4_hasIndex},
  {"_open", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_7_open, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_6_open},
  {"gettid", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_9gettid, METH_O, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_8gettid},
  {"getrname", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_11getrname, METH_O, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_10getrname},
  {"_parseRegion", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_13_parseRegion, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_12_parseRegion},
  {"reset", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_15reset, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_14reset},
  {"seek", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_17seek, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_16seek},
  {"tell", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_19tell, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_18tell},
  {"fetch", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_21fetch, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_20fetch},
  {"head", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_23head, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_22head},
  {"mate", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_25mate, METH_O, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_24mate},
  {"count", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_27count, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_26count},
  {"pileup", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_29pileup, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_28pileup},
  {"count_coverage", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_31count_coverage, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_30count_coverage},
  {"close", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_33close, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_32close},
  {"write", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_37write, METH_O, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_36write},
  {"__enter__", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_39__enter__, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_38__enter__},
  {"__exit__", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_41__exit__, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_40__exit__},
  {"_checkIndex", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_43_checkIndex, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_42_checkIndex},
  {"_buildLine", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_45_buildLine, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_44_buildLine},
  {"__next__", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_13AlignmentFile_49__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_48__next__},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_14calignmentfile_AlignmentFile[] = {
  {(char *)"filename", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_filename, 0, __pyx_k_filename_associated_with_this_ob, 0},
  {(char *)"nreferences", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_nreferences, 0, __pyx_k_number_of_term_reference_sequenc, 0},
  {(char *)"references", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_references, 0, __pyx_k_tuple_with_the_names_of_term_ref, 0},
  {(char *)"lengths", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_lengths, 0, __pyx_k_tuple_of_the_lengths_of_the_term, 0},
  {(char *)"mapped", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_mapped, 0, __pyx_k_total_number_of_mapped_alignment, 0},
  {(char *)"unmapped", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_unmapped, 0, __pyx_k_total_number_of_unmapped_reads_a, 0},
  {(char *)"nocoordinate", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_nocoordinate, 0, __pyx_k_total_number_of_reads_without_co, 0},
  {(char *)"text", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_text, 0, __pyx_k_full_contents_of_the_term_sam_fi, 0},
  {(char *)"header", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_header, 0, __pyx_k_header_information_within_the_te, 0},
  {(char *)"is_bam", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_is_bam, 0, 0, 0},
  {(char *)"is_cram", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_is_cram, 0, 0, 0},
  {(char *)"is_stream", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_is_stream, 0, 0, 0},
  {(char *)"is_remote", __pyx_getprop_5pysam_14calignmentfile_13AlignmentFile_is_remote, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_AlignmentFile = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.AlignmentFile", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_AlignmentFile, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "*(filename, mode=None, template = None,\n         reference_names=None, reference_lengths = None,\n         text=NULL, header=None,\n         add_sq_text=False, check_header=True,\n         check_sq=True)*\n\n    A :term:`SAM`/:term:`BAM` formatted file. The file is\n    automatically opened.\n\n    *mode* should be ``r`` for reading or ``w`` for writing. The\n    default is text mode (:term:`SAM`). For binary (:term:`BAM`) I/O\n    you should append ``b`` for compressed or ``u`` for uncompressed\n    :term:`BAM` output.  Use ``h`` to output header information in\n    text (:term:`TAM`) mode.\n\n    If ``b`` is present, it must immediately follow ``r`` or ``w``.\n    Valid modes are ``r``, ``w``, ``wh``, ``rb``, ``wb``, ``wbu`` and\n    ``wb0``. For instance, to open a :term:`BAM` formatted file for\n    reading, type::\n\n        f = pysam.AlignmentFile('ex1.bam','rb')\n\n    If mode is not specified, we will try to auto-detect in the order\n    'rb', 'r', thus both the following should work::\n\n        f1 = pysam.AlignmentFile('ex1.bam')\n        f2 = pysam.AlignmentFile('ex1.sam')\n\n    If an index for a BAM file exists (.bai), it will be opened\n    automatically. Without an index random access to reads via\n    :meth:`fetch` and :meth:`pileup` is disabled.\n\n    For writing, the header of a :term:`SAM` file/:term:`BAM` file can\n    be constituted from several sources (see also the samtools format\n    specification):\n\n        1. If *template* is given, the header is copied from a another\n           *AlignmentFile* (*template* must be of type *AlignmentFile*).\n\n        2. If *header* is given, the header is built from a\n           multi-level dictionary. The first level are the four types\n           ('HD', 'SQ', ...). The second level are a list of lines,\n           with each line being a list of tag-value pairs. The header\n           is constructed first from all the defined fields, followed\n           by user tags in alphabetical order.\n\n        3. If *text* is given, new header text is copied from raw\n           text.\n\n        4. The names (*reference_names*) and lengths\n           (*reference_lengths*) are supplied directly as lists.  By\n           default, 'SQ' and 'LN' tags will be added to the header\n           text. This option can be changed by unsetting the flag\n           *add_sq_text*.\n\n    For writing a CRAM file, the filename of the reference can be \n    added through a fasta formatted file (*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    chromosome names (*check_sq* = True).\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile_AlignmentFile, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_AlignmentFile, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_47__iter__, /*tp_iter*/
  __pyx_pw_5pysam_14calignmentfile_13AlignmentFile_49__next__, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_AlignmentFile, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_14calignmentfile_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_14calignmentfile_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
};

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_PileupColumn(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_14calignmentfile_PileupColumn(PyObject *o) {
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_12PileupColumn_reference_id(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_12PileupColumn_12reference_id_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_12PileupColumn_nsegments(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_12PileupColumn_9nsegments_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_12PileupColumn_nsegments(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_12PileupColumn_9nsegments_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_12PileupColumn_reference_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_12PileupColumn_13reference_pos_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_12PileupColumn_pileups(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_12PileupColumn_7pileups_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_12PileupColumn_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_12PileupColumn_3pos_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_12PileupColumn_pos(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_12PileupColumn_3pos_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_12PileupColumn_tid(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_12PileupColumn_3tid_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_12PileupColumn_tid(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_12PileupColumn_3tid_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_12PileupColumn_n(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_12PileupColumn_1n_1__get__(o);
}

static int __pyx_setprop_5pysam_14calignmentfile_12PileupColumn_n(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {
  if (v) {
    return __pyx_pw_5pysam_14calignmentfile_12PileupColumn_1n_3__set__(o, v);
  }
  else {
    PyErr_SetString(PyExc_NotImplementedError, "__del__");
    return -1;
  }
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_PileupColumn[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_14calignmentfile_PileupColumn[] = {
  {(char *)"reference_id", __pyx_getprop_5pysam_14calignmentfile_12PileupColumn_reference_id, 0, __pyx_k_the_reference_sequence_number_as, 0},
  {(char *)"nsegments", __pyx_getprop_5pysam_14calignmentfile_12PileupColumn_nsegments, __pyx_setprop_5pysam_14calignmentfile_12PileupColumn_nsegments, __pyx_k_number_of_reads_mapping_to_this, 0},
  {(char *)"reference_pos", __pyx_getprop_5pysam_14calignmentfile_12PileupColumn_reference_pos, 0, __pyx_k_the_position_in_the_reference_se, 0},
  {(char *)"pileups", __pyx_getprop_5pysam_14calignmentfile_12PileupColumn_pileups, 0, __pyx_k_list_of_reads_class_pysam_Pileup, 0},
  {(char *)"pos", __pyx_getprop_5pysam_14calignmentfile_12PileupColumn_pos, __pyx_setprop_5pysam_14calignmentfile_12PileupColumn_pos, 0, 0},
  {(char *)"tid", __pyx_getprop_5pysam_14calignmentfile_12PileupColumn_tid, __pyx_setprop_5pysam_14calignmentfile_12PileupColumn_tid, 0, 0},
  {(char *)"n", __pyx_getprop_5pysam_14calignmentfile_12PileupColumn_n, __pyx_setprop_5pysam_14calignmentfile_12PileupColumn_n, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_PileupColumn = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.PileupColumn", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_PileupColumn), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_PileupColumn, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_14calignmentfile_12PileupColumn_3__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  "PileupColumn()\nA pileup of reads at a particular reference sequence postion\n    (:term:`column`). A pileup column contains all the reads that map\n    to a certain target base.\n\n    This class is a proxy for results returned by the samtools pileup\n    engine.  If the underlying engine iterator advances, the results\n    of this column will change.\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_14calignmentfile_PileupColumn, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_14calignmentfile_PileupColumn, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5pysam_14calignmentfile_12PileupColumn_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile_PileupColumn, /*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
};

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_PileupRead(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_PileupRead *p;
  PyObject *o;
  if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {
    o = (*t->tp_alloc)(t, 0);
  } else {
    o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0);
  }
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)o);
  p->_alignment = ((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_14calignmentfile_PileupRead(PyObject *o) {
  struct __pyx_obj_5pysam_14calignmentfile_PileupRead *p = (struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->_alignment);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_14calignmentfile_PileupRead(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_14calignmentfile_PileupRead *p = (struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)o;
  if (p->_alignment) {
    e = (*v)(((PyObject*)p->_alignment), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_14calignmentfile_PileupRead(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_14calignmentfile_PileupRead *p = (struct __pyx_obj_5pysam_14calignmentfile_PileupRead *)o;
  tmp = ((PyObject*)p->_alignment);
  p->_alignment = ((struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_10PileupRead_alignment(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_10PileupRead_9alignment_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_10PileupRead_query_position(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_10PileupRead_14query_position_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_10PileupRead_indel(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_10PileupRead_5indel_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_10PileupRead_level(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_10PileupRead_5level_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_10PileupRead_is_del(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_10PileupRead_6is_del_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_10PileupRead_is_head(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_10PileupRead_7is_head_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_10PileupRead_is_tail(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_10PileupRead_7is_tail_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_10PileupRead_is_refskip(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_10PileupRead_10is_refskip_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_PileupRead[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_14calignmentfile_PileupRead[] = {
  {(char *)"alignment", __pyx_getprop_5pysam_14calignmentfile_10PileupRead_alignment, 0, __pyx_k_a_class_pysam_AlignedSegment_obj, 0},
  {(char *)"query_position", __pyx_getprop_5pysam_14calignmentfile_10PileupRead_query_position, 0, __pyx_k_position_of_the_read_base_at_the, 0},
  {(char *)"indel", __pyx_getprop_5pysam_14calignmentfile_10PileupRead_indel, 0, __pyx_k_indel_length_0_for_no_indel_posi, 0},
  {(char *)"level", __pyx_getprop_5pysam_14calignmentfile_10PileupRead_level, 0, __pyx_k_the_level_of_the_read_in_the_vie, 0},
  {(char *)"is_del", __pyx_getprop_5pysam_14calignmentfile_10PileupRead_is_del, 0, __pyx_k_1_iff_the_base_on_the_padded_rea, 0},
  {(char *)"is_head", __pyx_getprop_5pysam_14calignmentfile_10PileupRead_is_head, 0, 0, 0},
  {(char *)"is_tail", __pyx_getprop_5pysam_14calignmentfile_10PileupRead_is_tail, 0, 0, 0},
  {(char *)"is_refskip", __pyx_getprop_5pysam_14calignmentfile_10PileupRead_is_refskip, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_PileupRead = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.PileupRead", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_PileupRead), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_PileupRead, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_14calignmentfile_10PileupRead_3__str__, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "PileupRead()\nRepresentation of a read aligned to a particular position in the\n    reference sequence.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile_PileupRead, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_PileupRead, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_PileupRead, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_14calignmentfile_PileupRead, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_pw_5pysam_14calignmentfile_10PileupRead_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile_PileupRead, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRow(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_IteratorRow *)o);
  p->samfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRow(PyObject *o) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow *p = (struct __pyx_obj_5pysam_14calignmentfile_IteratorRow *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_14calignmentfile_11IteratorRow_3__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->samfile);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_14calignmentfile_IteratorRow(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow *p = (struct __pyx_obj_5pysam_14calignmentfile_IteratorRow *)o;
  if (p->samfile) {
    e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_14calignmentfile_IteratorRow(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRow *p = (struct __pyx_obj_5pysam_14calignmentfile_IteratorRow *)o;
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_IteratorRow[] = {
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_IteratorRow = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.IteratorRow", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRow), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRow, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "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        explicitely. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_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_14calignmentfile_11IteratorRow_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile_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
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowRegion __pyx_vtable_5pysam_14calignmentfile_IteratorRowRegion;

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRowRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *p;
  PyObject *o = __pyx_tp_new_5pysam_14calignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowRegion;
  return o;
}

static void __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRowRegion(PyObject *o) {
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_7__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRow(o);
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_IteratorRowRegion[] = {
  {"__next__", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_5__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_5pysam_14calignmentfile_17IteratorRowRegion_4__next__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_IteratorRowRegion = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.IteratorRowRegion", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRowRegion, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "IteratorRowRegion(AlignmentFile samfile, int tid, int beg, int end, int multiple_iterators=False)\n*(AlignmentFile samfile, int tid, int beg, int end,\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        explicitely. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_14calignmentfile_17IteratorRowRegion_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_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_14calignmentfile_17IteratorRowRegion_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile_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
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowHead __pyx_vtable_5pysam_14calignmentfile_IteratorRowHead;

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRowHead(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *p;
  PyObject *o = __pyx_tp_new_5pysam_14calignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowHead;
  return o;
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_IteratorRowHead[] = {
  {"__next__", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_15IteratorRowHead_5__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_5pysam_14calignmentfile_15IteratorRowHead_4__next__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_IteratorRowHead = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.IteratorRowHead", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRow, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "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_14calignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_14calignmentfile_15IteratorRowHead_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_14calignmentfile_15IteratorRowHead_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_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_14calignmentfile_15IteratorRowHead_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile_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
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowAll __pyx_vtable_5pysam_14calignmentfile_IteratorRowAll;

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRowAll(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *p;
  PyObject *o = __pyx_tp_new_5pysam_14calignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowAll;
  return o;
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_IteratorRowAll[] = {
  {"__next__", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14IteratorRowAll_5__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_5pysam_14calignmentfile_14IteratorRowAll_4__next__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_IteratorRowAll = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.IteratorRowAll", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRow, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "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_14calignmentfile_IteratorRow, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_IteratorRow, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_14calignmentfile_14IteratorRowAll_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_14calignmentfile_14IteratorRowAll_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_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_14calignmentfile_14IteratorRowAll_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile_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
};

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRowAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *p;
  PyObject *o = __pyx_tp_new_5pysam_14calignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *)o);
  p->rowiter = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRowAllRefs(PyObject *o) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->rowiter);
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRow(o);
}

static int __pyx_tp_traverse_5pysam_14calignmentfile_IteratorRowAllRefs(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *)o;
  e = __pyx_tp_traverse_5pysam_14calignmentfile_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_14calignmentfile_IteratorRowAllRefs(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *p = (struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs *)o;
  __pyx_tp_clear_5pysam_14calignmentfile_IteratorRow(o);
  tmp = ((PyObject*)p->rowiter);
  p->rowiter = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_IteratorRowAllRefs[] = {
  {"nextiter", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_18IteratorRowAllRefs_3nextiter, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_18IteratorRowAllRefs_2nextiter},
  {"__next__", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_18IteratorRowAllRefs_7__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_5pysam_14calignmentfile_18IteratorRowAllRefs_6__next__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_IteratorRowAllRefs = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.IteratorRowAllRefs", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAllRefs), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRowAllRefs, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "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        explicitely. It is returned as a result of call to a\n        :meth:`AlignmentFile.fetch`.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile_IteratorRowAllRefs, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_IteratorRowAllRefs, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_14calignmentfile_18IteratorRowAllRefs_5__iter__, /*tp_iter*/
  __pyx_pw_5pysam_14calignmentfile_18IteratorRowAllRefs_7__next__, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_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_14calignmentfile_18IteratorRowAllRefs_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile_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
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorRowSelection __pyx_vtable_5pysam_14calignmentfile_IteratorRowSelection;

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorRowSelection(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *p;
  PyObject *o = __pyx_tp_new_5pysam_14calignmentfile_IteratorRow(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowSelection;
  p->positions = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRowSelection(PyObject *o) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->positions);
  PyObject_GC_Track(o);
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRow(o);
}

static int __pyx_tp_traverse_5pysam_14calignmentfile_IteratorRowSelection(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *)o;
  e = __pyx_tp_traverse_5pysam_14calignmentfile_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_14calignmentfile_IteratorRowSelection(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *p = (struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *)o;
  __pyx_tp_clear_5pysam_14calignmentfile_IteratorRow(o);
  tmp = ((PyObject*)p->positions);
  p->positions = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_IteratorRowSelection[] = {
  {"__next__", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_20IteratorRowSelection_5__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_5pysam_14calignmentfile_20IteratorRowSelection_4__next__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_IteratorRowSelection = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.IteratorRowSelection", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorRowSelection, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "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        explicitely. It is returned as a result of call to a :meth:`AlignmentFile.fetch`.\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile_IteratorRowSelection, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_IteratorRowSelection, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_14calignmentfile_20IteratorRowSelection_3__iter__, /*tp_iter*/
  __pyx_pw_5pysam_14calignmentfile_20IteratorRowSelection_5__next__, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_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_14calignmentfile_20IteratorRowSelection_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile_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
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn __pyx_vtable_5pysam_14calignmentfile_IteratorColumn;

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorColumn(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_IteratorColumn *)o);
  p->__pyx_vtab = __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumn;
  p->iter = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  p->samfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  p->fastafile = ((struct __pyx_obj_5pysam_6cfaidx_Fastafile *)Py_None); Py_INCREF(Py_None);
  p->stepper = Py_None; Py_INCREF(Py_None);
  if (unlikely(__pyx_pw_5pysam_14calignmentfile_14IteratorColumn_1__cinit__(o, a, k) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorColumn(PyObject *o) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *p = (struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_14calignmentfile_14IteratorColumn_9__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->iter);
  Py_CLEAR(p->samfile);
  Py_CLEAR(p->fastafile);
  Py_CLEAR(p->stepper);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_14calignmentfile_IteratorColumn(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *p = (struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_IteratorColumn(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *p = (struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *)o;
  tmp = ((PyObject*)p->iter);
  p->iter = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->fastafile);
  p->fastafile = ((struct __pyx_obj_5pysam_6cfaidx_Fastafile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->stepper);
  p->stepper = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_14IteratorColumn_seq_len(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_14IteratorColumn_7seq_len_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_IteratorColumn[] = {
  {"addReference", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14IteratorColumn_5addReference, METH_O, __pyx_doc_5pysam_14calignmentfile_14IteratorColumn_4addReference},
  {"hasReference", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_14IteratorColumn_7hasReference, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_14IteratorColumn_6hasReference},
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_14calignmentfile_IteratorColumn[] = {
  {(char *)"seq_len", __pyx_getprop_5pysam_14calignmentfile_14IteratorColumn_seq_len, 0, __pyx_k_current_sequence_length, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_IteratorColumn = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.IteratorColumn", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorColumn, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "abstract base class for iterators over columns.\n\n    IteratorColumn objects wrap the pileup functionality of samtools.\n\n    For reasons of efficiency, the iterator points to the current\n    pileup buffer. The pileup buffer is updated at every iteration.\n    This might cause some unexpected behavious. For example,\n    consider the conversion to a list::\n\n       f = AlignmentFile(\"file.bam\", \"rb\")\n       result = list( f.pileup() )\n\n    Here, ``result`` will contain ``n`` objects of type\n    :class:`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:`PileupRead`.\n\n    If the iterator is associated with a :class:`Fastafile` using the\n    :meth:`addReference` method, then the iterator will export the\n    current sequence via the methods :meth:`getSequence` and\n    :meth:`seq_len`.\n\n    Optional kwargs to the iterator:\n\n    stepper\n       The stepper controls how the iterator advances.\n\n       Valid values are None, \"all\" (default), \"nofilter\" or \"samtools\".\n\n       See AlignmentFile.pileup for description.\n    \n    fastafile\n       A :class:`FastaFile` object\n\n    max_depth\n       maximum read depth. The default is 8000.\n\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  __pyx_pw_5pysam_14calignmentfile_14IteratorColumn_3__iter__, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_IteratorColumn, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_14calignmentfile_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_14calignmentfile_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
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnRegion __pyx_vtable_5pysam_14calignmentfile_IteratorColumnRegion;

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorColumnRegion(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion *p;
  PyObject *o = __pyx_tp_new_5pysam_14calignmentfile_IteratorColumn(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn*)__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnRegion;
  if (unlikely(__pyx_pw_5pysam_14calignmentfile_20IteratorColumnRegion_1__cinit__(o, a, k) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_IteratorColumnRegion[] = {
  {"__next__", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_20IteratorColumnRegion_3__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_5pysam_14calignmentfile_20IteratorColumnRegion_2__next__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_IteratorColumnRegion = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.IteratorColumnRegion", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnRegion), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorColumn, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "iterates over a region only.\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_5pysam_14calignmentfile_14IteratorColumn_3__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  __pyx_pw_5pysam_14calignmentfile_20IteratorColumnRegion_3__next__, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_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_14calignmentfile_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
};
static struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumnAllRefs __pyx_vtable_5pysam_14calignmentfile_IteratorColumnAllRefs;

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IteratorColumnAllRefs(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs *p;
  PyObject *o = __pyx_tp_new_5pysam_14calignmentfile_IteratorColumn(t, a, k);
  if (unlikely(!o)) return 0;
  p = ((struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs *)o);
  p->__pyx_base.__pyx_vtab = (struct __pyx_vtabstruct_5pysam_14calignmentfile_IteratorColumn*)__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnAllRefs;
  if (unlikely(__pyx_pw_5pysam_14calignmentfile_21IteratorColumnAllRefs_1__cinit__(o, a, k) < 0)) {
    Py_DECREF(o); o = 0;
  }
  return o;
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_IteratorColumnAllRefs[] = {
  {"__next__", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_21IteratorColumnAllRefs_3__next__, METH_NOARGS|METH_COEXIST, __pyx_doc_5pysam_14calignmentfile_21IteratorColumnAllRefs_2__next__},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_IteratorColumnAllRefs = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.IteratorColumnAllRefs", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumnAllRefs), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_IteratorColumn, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "iterates over all columns by chaining iterators over each reference\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile_IteratorColumn, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_IteratorColumn, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  #if CYTHON_COMPILING_IN_PYPY
  __pyx_pw_5pysam_14calignmentfile_14IteratorColumn_3__iter__, /*tp_iter*/
  #else
  0, /*tp_iter*/
  #endif
  __pyx_pw_5pysam_14calignmentfile_21IteratorColumnAllRefs_3__next__, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_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_14calignmentfile_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
};

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_IndexedReads(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_5pysam_14calignmentfile_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_14calignmentfile_IndexedReads *)o);
  p->samfile = ((struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *)Py_None); Py_INCREF(Py_None);
  p->index = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_5pysam_14calignmentfile_IndexedReads(PyObject *o) {
  struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *p = (struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *)o;
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && !_PyGC_FINALIZED(o)) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  PyObject_GC_UnTrack(o);
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++Py_REFCNT(o);
    __pyx_pw_5pysam_14calignmentfile_12IndexedReads_7__dealloc__(o);
    --Py_REFCNT(o);
    PyErr_Restore(etype, eval, etb);
  }
  Py_CLEAR(p->samfile);
  Py_CLEAR(p->index);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_5pysam_14calignmentfile_IndexedReads(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *p = (struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *)o;
  if (p->samfile) {
    e = (*v)(((PyObject*)p->samfile), a); if (e) return e;
  }
  if (p->index) {
    e = (*v)(p->index, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_14calignmentfile_IndexedReads(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *p = (struct __pyx_obj_5pysam_14calignmentfile_IndexedReads *)o;
  tmp = ((PyObject*)p->samfile);
  p->samfile = ((struct __pyx_obj_5pysam_14calignmentfile_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);
  return 0;
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_IndexedReads[] = {
  {"build", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_12IndexedReads_3build, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_12IndexedReads_2build},
  {"find", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_12IndexedReads_5find, METH_O, __pyx_doc_5pysam_14calignmentfile_12IndexedReads_4find},
  {0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_IndexedReads = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.IndexedReads", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_IndexedReads), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_IndexedReads, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "IndexedReads(AlignmentFile samfile, int multiple_iterators=True)\nindex a Sam/BAM-file by query name.\n\n    The index is kept in memory and can be substantial.\n\n    By default, the file is re-openend to avoid conflicts if multiple\n    operators work on the same file. Set *multiple_iterators* = False\n    to not re-open *samfile*.\n    ", /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile_IndexedReads, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile_IndexedReads, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_5pysam_14calignmentfile_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_14calignmentfile_12IndexedReads_1__init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile_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
};

static PyObject *__pyx_tp_new_5pysam_14calignmentfile_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_14calignmentfile_SNPCall(PyObject *o) {
  #if PY_VERSION_HEX >= 0x030400a1
  if (unlikely(Py_TYPE(o)->tp_finalize) && (!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))) {
    if (PyObject_CallFinalizerFromDealloc(o)) return;
  }
  #endif
  (*Py_TYPE(o)->tp_free)(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_7SNPCall_tid(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_7SNPCall_3tid_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_7SNPCall_pos(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_7SNPCall_3pos_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_7SNPCall_reference_base(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_7SNPCall_14reference_base_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_7SNPCall_genotype(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_7SNPCall_8genotype_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_7SNPCall_consensus_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_7SNPCall_17consensus_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_7SNPCall_snp_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_7SNPCall_11snp_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_7SNPCall_mapping_quality(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_7SNPCall_15mapping_quality_1__get__(o);
}

static PyObject *__pyx_getprop_5pysam_14calignmentfile_7SNPCall_coverage(PyObject *o, CYTHON_UNUSED void *x) {
  return __pyx_pw_5pysam_14calignmentfile_7SNPCall_8coverage_1__get__(o);
}

static PyMethodDef __pyx_methods_5pysam_14calignmentfile_SNPCall[] = {
  {0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_5pysam_14calignmentfile_SNPCall[] = {
  {(char *)"tid", __pyx_getprop_5pysam_14calignmentfile_7SNPCall_tid, 0, __pyx_k_the_chromosome_ID_as_is_defined, 0},
  {(char *)"pos", __pyx_getprop_5pysam_14calignmentfile_7SNPCall_pos, 0, __pyx_k_nucleotide_position_of_SNP, 0},
  {(char *)"reference_base", __pyx_getprop_5pysam_14calignmentfile_7SNPCall_reference_base, 0, __pyx_k_reference_base_at_pos_N_if_no_re, 0},
  {(char *)"genotype", __pyx_getprop_5pysam_14calignmentfile_7SNPCall_genotype, 0, __pyx_k_the_genotype_called, 0},
  {(char *)"consensus_quality", __pyx_getprop_5pysam_14calignmentfile_7SNPCall_consensus_quality, 0, __pyx_k_the_genotype_quality_Phred_scale, 0},
  {(char *)"snp_quality", __pyx_getprop_5pysam_14calignmentfile_7SNPCall_snp_quality, 0, __pyx_k_the_snp_quality_Phred_scaled_pro, 0},
  {(char *)"mapping_quality", __pyx_getprop_5pysam_14calignmentfile_7SNPCall_mapping_quality, 0, __pyx_k_the_root_mean_square_rms_of_the, 0},
  {(char *)"coverage", __pyx_getprop_5pysam_14calignmentfile_7SNPCall_coverage, 0, __pyx_k_coverage_or_read_depth_the_numbe, 0},
  {0, 0, 0, 0, 0}
};

static PyTypeObject __pyx_type_5pysam_14calignmentfile_SNPCall = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.SNPCall", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile_SNPCall), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile_SNPCall, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  __pyx_pw_5pysam_14calignmentfile_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_14calignmentfile_SNPCall, /*tp_methods*/
  0, /*tp_members*/
  __pyx_getsets_5pysam_14calignmentfile_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_14calignmentfile_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
};

static struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr *__pyx_freelist_5pysam_14calignmentfile___pyx_scope_struct__genexpr[8];
static int __pyx_freecount_5pysam_14calignmentfile___pyx_scope_struct__genexpr = 0;

static PyObject *__pyx_tp_new_5pysam_14calignmentfile___pyx_scope_struct__genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_14calignmentfile___pyx_scope_struct__genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr)))) {
    o = (PyObject*)__pyx_freelist_5pysam_14calignmentfile___pyx_scope_struct__genexpr[--__pyx_freecount_5pysam_14calignmentfile___pyx_scope_struct__genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_14calignmentfile___pyx_scope_struct__genexpr(PyObject *o) {
  struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_x);
  Py_CLEAR(p->__pyx_v_y);
  Py_CLEAR(p->__pyx_t_0);
  Py_CLEAR(p->__pyx_t_1);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_14calignmentfile___pyx_scope_struct__genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr)))) {
    __pyx_freelist_5pysam_14calignmentfile___pyx_scope_struct__genexpr[__pyx_freecount_5pysam_14calignmentfile___pyx_scope_struct__genexpr++] = ((struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5pysam_14calignmentfile___pyx_scope_struct__genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr *)o;
  if (p->__pyx_v_x) {
    e = (*v)(p->__pyx_v_x, a); if (e) return e;
  }
  if (p->__pyx_v_y) {
    e = (*v)(p->__pyx_v_y, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  if (p->__pyx_t_1) {
    e = (*v)(p->__pyx_t_1, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_14calignmentfile___pyx_scope_struct__genexpr(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr *p = (struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr *)o;
  tmp = ((PyObject*)p->__pyx_v_x);
  p->__pyx_v_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_y);
  p->__pyx_v_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_0);
  p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_1);
  p->__pyx_t_1 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_5pysam_14calignmentfile___pyx_scope_struct__genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.__pyx_scope_struct__genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct__genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile___pyx_scope_struct__genexpr, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile___pyx_scope_struct__genexpr, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile___pyx_scope_struct__genexpr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile___pyx_scope_struct__genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr *__pyx_freelist_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr[8];
static int __pyx_freecount_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr = 0;

static PyObject *__pyx_tp_new_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  PyObject *o;
  if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr)))) {
    o = (PyObject*)__pyx_freelist_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr[--__pyx_freecount_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr];
    memset(o, 0, sizeof(struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr));
    (void) PyObject_INIT(o, t);
    PyObject_GC_Track(o);
  } else {
    o = (*t->tp_alloc)(t, 0);
    if (unlikely(!o)) return 0;
  }
  return o;
}

static void __pyx_tp_dealloc_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr(PyObject *o) {
  struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_x);
  Py_CLEAR(p->__pyx_v_y);
  Py_CLEAR(p->__pyx_t_0);
  Py_CLEAR(p->__pyx_t_1);
  if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr)))) {
    __pyx_freelist_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr[__pyx_freecount_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr *)o);
  } else {
    (*Py_TYPE(o)->tp_free)(o);
  }
}

static int __pyx_tp_traverse_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr *)o;
  if (p->__pyx_v_x) {
    e = (*v)(p->__pyx_v_x, a); if (e) return e;
  }
  if (p->__pyx_v_y) {
    e = (*v)(p->__pyx_v_y, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  if (p->__pyx_t_1) {
    e = (*v)(p->__pyx_t_1, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr(PyObject *o) {
  PyObject* tmp;
  struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr *)o;
  tmp = ((PyObject*)p->__pyx_v_x);
  p->__pyx_v_x = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_y);
  p->__pyx_v_y = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_0);
  p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_t_1);
  p->__pyx_t_1 = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  return 0;
}

static PyTypeObject __pyx_type_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  "pysam.calignmentfile.__pyx_scope_struct_1_genexpr", /*tp_name*/
  sizeof(struct __pyx_obj_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  0, /*tp_as_number*/
  0, /*tp_as_sequence*/
  0, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  0, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr, /*tp_traverse*/
  __pyx_tp_clear_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  0, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  0, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  0, /*tp_version_tag*/
  #if PY_VERSION_HEX >= 0x030400a1
  0, /*tp_finalize*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {"set_verbosity", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_5set_verbosity, METH_O, __pyx_doc_5pysam_14calignmentfile_4set_verbosity},
  {"get_verbosity", (PyCFunction)__pyx_pw_5pysam_14calignmentfile_7get_verbosity, METH_NOARGS, __pyx_doc_5pysam_14calignmentfile_6get_verbosity},
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
  #if PY_VERSION_HEX < 0x03020000
    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  #else
    PyModuleDef_HEAD_INIT,
  #endif
    "calignmentfile",
    0, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_kp_s_2sc_is, __pyx_k_2sc_is, sizeof(__pyx_k_2sc_is), 0, 0, 1, 0},
  {&__pyx_kp_s_2sc_s, __pyx_k_2sc_s, sizeof(__pyx_k_2sc_s), 0, 0, 1, 0},
  {&__pyx_kp_s_2sccI_i_s, __pyx_k_2sccI_i_s, sizeof(__pyx_k_2sccI_i_s), 0, 0, 1, 0},
  {&__pyx_n_b_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 0, 1},
  {&__pyx_n_s_A, __pyx_k_A, sizeof(__pyx_k_A), 0, 0, 1, 1},
  {&__pyx_n_s_AS, __pyx_k_AS, sizeof(__pyx_k_AS), 0, 0, 1, 1},
  {&__pyx_n_s_AlignedSegment, __pyx_k_AlignedSegment, sizeof(__pyx_k_AlignedSegment), 0, 0, 1, 1},
  {&__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_kp_u_Argument_must_be_string_bytes_or, __pyx_k_Argument_must_be_string_bytes_or, sizeof(__pyx_k_Argument_must_be_string_bytes_or), 0, 1, 0, 0},
  {&__pyx_kp_u_Argument_must_be_string_or_unico, __pyx_k_Argument_must_be_string_or_unico, sizeof(__pyx_k_Argument_must_be_string_or_unico), 0, 1, 0, 0},
  {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1},
  {&__pyx_n_b_B, __pyx_k_B, sizeof(__pyx_k_B), 0, 0, 0, 1},
  {&__pyx_n_s_B, __pyx_k_B, sizeof(__pyx_k_B), 0, 0, 1, 1},
  {&__pyx_n_b_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 0, 1},
  {&__pyx_n_s_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 1, 1},
  {&__pyx_n_s_CIGAR2CODE, __pyx_k_CIGAR2CODE, sizeof(__pyx_k_CIGAR2CODE), 0, 0, 1, 1},
  {&__pyx_n_s_CIGAR_REGEX, __pyx_k_CIGAR_REGEX, sizeof(__pyx_k_CIGAR_REGEX), 0, 0, 1, 1},
  {&__pyx_n_s_CL, __pyx_k_CL, sizeof(__pyx_k_CL), 0, 0, 1, 1},
  {&__pyx_n_s_CN, __pyx_k_CN, sizeof(__pyx_k_CN), 0, 0, 1, 1},
  {&__pyx_n_s_CO, __pyx_k_CO, sizeof(__pyx_k_CO), 0, 0, 1, 1},
  {&__pyx_n_s_D, __pyx_k_D, sizeof(__pyx_k_D), 0, 0, 1, 1},
  {&__pyx_n_s_DS, __pyx_k_DS, sizeof(__pyx_k_DS), 0, 0, 1, 1},
  {&__pyx_n_s_DT, __pyx_k_DT, sizeof(__pyx_k_DT), 0, 0, 1, 1},
  {&__pyx_n_s_F, __pyx_k_F, sizeof(__pyx_k_F), 0, 0, 1, 1},
  {&__pyx_n_s_FO, __pyx_k_FO, sizeof(__pyx_k_FO), 0, 0, 1, 1},
  {&__pyx_n_s_GO, __pyx_k_GO, sizeof(__pyx_k_GO), 0, 0, 1, 1},
  {&__pyx_n_s_H, __pyx_k_H, sizeof(__pyx_k_H), 0, 0, 1, 1},
  {&__pyx_n_s_HD, __pyx_k_HD, sizeof(__pyx_k_HD), 0, 0, 1, 1},
  {&__pyx_n_b_I, __pyx_k_I, sizeof(__pyx_k_I), 0, 0, 0, 1},
  {&__pyx_n_s_I, __pyx_k_I, sizeof(__pyx_k_I), 0, 0, 1, 1},
  {&__pyx_n_s_ID, __pyx_k_ID, sizeof(__pyx_k_ID), 0, 0, 1, 1},
  {&__pyx_n_s_IOError, __pyx_k_IOError, sizeof(__pyx_k_IOError), 0, 0, 1, 1},
  {&__pyx_n_s_IS_PYTHON3, __pyx_k_IS_PYTHON3, sizeof(__pyx_k_IS_PYTHON3), 0, 0, 1, 1},
  {&__pyx_kp_s_I_O_operation_on_closed_file, __pyx_k_I_O_operation_on_closed_file, sizeof(__pyx_k_I_O_operation_on_closed_file), 0, 0, 1, 0},
  {&__pyx_n_s_IndexedReads, __pyx_k_IndexedReads, sizeof(__pyx_k_IndexedReads), 0, 0, 1, 1},
  {&__pyx_kp_s_Invalid_tag_s, __pyx_k_Invalid_tag_s, sizeof(__pyx_k_Invalid_tag_s), 0, 0, 1, 0},
  {&__pyx_n_s_IteratorColumn, __pyx_k_IteratorColumn, sizeof(__pyx_k_IteratorColumn), 0, 0, 1, 1},
  {&__pyx_n_s_IteratorRow, __pyx_k_IteratorRow, sizeof(__pyx_k_IteratorRow), 0, 0, 1, 1},
  {&__pyx_n_s_KS, __pyx_k_KS, sizeof(__pyx_k_KS), 0, 0, 1, 1},
  {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1},
  {&__pyx_n_s_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_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1},
  {&__pyx_n_s_NotImplemented, __pyx_k_NotImplemented, sizeof(__pyx_k_NotImplemented), 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_OverflowError, __pyx_k_OverflowError, sizeof(__pyx_k_OverflowError), 0, 0, 1, 1},
  {&__pyx_n_s_PG, __pyx_k_PG, sizeof(__pyx_k_PG), 0, 0, 1, 1},
  {&__pyx_n_s_PI, __pyx_k_PI, sizeof(__pyx_k_PI), 0, 0, 1, 1},
  {&__pyx_n_s_PL, __pyx_k_PL, sizeof(__pyx_k_PL), 0, 0, 1, 1},
  {&__pyx_n_s_PN, __pyx_k_PN, sizeof(__pyx_k_PN), 0, 0, 1, 1},
  {&__pyx_n_s_PP, __pyx_k_PP, sizeof(__pyx_k_PP), 0, 0, 1, 1},
  {&__pyx_n_s_PU, __pyx_k_PU, sizeof(__pyx_k_PU), 0, 0, 1, 1},
  {&__pyx_kp_s_Padding_BAM_CPAD_6_is_currently, __pyx_k_Padding_BAM_CPAD_6_is_currently, sizeof(__pyx_k_Padding_BAM_CPAD_6_is_currently), 0, 0, 1, 0},
  {&__pyx_n_s_PileupColumn, __pyx_k_PileupColumn, sizeof(__pyx_k_PileupColumn), 0, 0, 1, 1},
  {&__pyx_kp_s_PileupColumn_accessed_after_iter, __pyx_k_PileupColumn_accessed_after_iter, sizeof(__pyx_k_PileupColumn_accessed_after_iter), 0, 0, 1, 0},
  {&__pyx_n_s_PileupRead, __pyx_k_PileupRead, sizeof(__pyx_k_PileupRead), 0, 0, 1, 1},
  {&__pyx_n_s_RG, __pyx_k_RG, sizeof(__pyx_k_RG), 0, 0, 1, 1},
  {&__pyx_n_b_S, __pyx_k_S, sizeof(__pyx_k_S), 0, 0, 0, 1},
  {&__pyx_n_s_S, __pyx_k_S, sizeof(__pyx_k_S), 0, 0, 1, 1},
  {&__pyx_n_s_SM, __pyx_k_SM, sizeof(__pyx_k_SM), 0, 0, 1, 1},
  {&__pyx_n_s_SN, __pyx_k_SN, sizeof(__pyx_k_SN), 0, 0, 1, 1},
  {&__pyx_n_s_SO, __pyx_k_SO, sizeof(__pyx_k_SO), 0, 0, 1, 1},
  {&__pyx_n_s_SP, __pyx_k_SP, sizeof(__pyx_k_SP), 0, 0, 1, 1},
  {&__pyx_n_s_SQ, __pyx_k_SQ, sizeof(__pyx_k_SQ), 0, 0, 1, 1},
  {&__pyx_kp_s_SQ_SN_s_LN_s, __pyx_k_SQ_SN_s_LN_s, sizeof(__pyx_k_SQ_SN_s_LN_s), 0, 0, 1, 0},
  {&__pyx_n_s_StopIteration, __pyx_k_StopIteration, sizeof(__pyx_k_StopIteration), 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_kp_s_Unsupported_value_type_in_set_op, __pyx_k_Unsupported_value_type_in_set_op, sizeof(__pyx_k_Unsupported_value_type_in_set_op), 0, 0, 1, 0},
  {&__pyx_n_s_VALID_HEADERS, __pyx_k_VALID_HEADERS, sizeof(__pyx_k_VALID_HEADERS), 0, 0, 1, 1},
  {&__pyx_n_s_VALID_HEADER_FIELDS, __pyx_k_VALID_HEADER_FIELDS, sizeof(__pyx_k_VALID_HEADER_FIELDS), 0, 0, 1, 1},
  {&__pyx_n_s_VALID_HEADER_ORDER, __pyx_k_VALID_HEADER_ORDER, sizeof(__pyx_k_VALID_HEADER_ORDER), 0, 0, 1, 1},
  {&__pyx_n_s_VALID_HEADER_TYPES, __pyx_k_VALID_HEADER_TYPES, sizeof(__pyx_k_VALID_HEADER_TYPES), 0, 0, 1, 1},
  {&__pyx_n_s_VN, __pyx_k_VN, sizeof(__pyx_k_VN), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_n_b_Z, __pyx_k_Z, sizeof(__pyx_k_Z), 0, 0, 0, 1},
  {&__pyx_n_s_Z, __pyx_k_Z, sizeof(__pyx_k_Z), 0, 0, 1, 1},
  {&__pyx_n_s_Zidf, __pyx_k_Zidf, sizeof(__pyx_k_Zidf), 0, 0, 1, 1},
  {&__pyx_kp_s__13, __pyx_k__13, sizeof(__pyx_k__13), 0, 0, 1, 0},
  {&__pyx_kp_b__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 0, 0},
  {&__pyx_kp_s__41, __pyx_k__41, sizeof(__pyx_k__41), 0, 0, 1, 0},
  {&__pyx_kp_s__43, __pyx_k__43, sizeof(__pyx_k__43), 0, 0, 1, 0},
  {&__pyx_kp_s__46, __pyx_k__46, sizeof(__pyx_k__46), 0, 0, 1, 0},
  {&__pyx_kp_s__50, __pyx_k__50, sizeof(__pyx_k__50), 0, 0, 1, 0},
  {&__pyx_kp_s__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 0, 1, 0},
  {&__pyx_kp_s__74, __pyx_k__74, sizeof(__pyx_k__74), 0, 0, 1, 0},
  {&__pyx_n_s_add_sq_text, __pyx_k_add_sq_text, sizeof(__pyx_k_add_sq_text), 0, 0, 1, 1},
  {&__pyx_n_s_alignment, __pyx_k_alignment, sizeof(__pyx_k_alignment), 0, 0, 1, 1},
  {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
  {&__pyx_n_s_all_2, __pyx_k_all_2, sizeof(__pyx_k_all_2), 0, 0, 1, 1},
  {&__pyx_n_s_always, __pyx_k_always, sizeof(__pyx_k_always), 0, 0, 1, 1},
  {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
  {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
  {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1},
  {&__pyx_n_s_ascii, __pyx_k_ascii, sizeof(__pyx_k_ascii), 0, 0, 1, 1},
  {&__pyx_kp_s_at_least_one_integer_out_of_rang, __pyx_k_at_least_one_integer_out_of_rang, sizeof(__pyx_k_at_least_one_integer_out_of_rang), 0, 0, 1, 0},
  {&__pyx_kp_s_at_least_one_signed_integer_out, __pyx_k_at_least_one_signed_integer_out, sizeof(__pyx_k_at_least_one_signed_integer_out), 0, 0, 1, 0},
  {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
  {&__pyx_kp_b_bai, __pyx_k_bai, sizeof(__pyx_k_bai), 0, 0, 0, 0},
  {&__pyx_n_s_beg, __pyx_k_beg, sizeof(__pyx_k_beg), 0, 0, 1, 1},
  {&__pyx_n_s_buildLine, __pyx_k_buildLine, sizeof(__pyx_k_buildLine), 0, 0, 1, 1},
  {&__pyx_n_b_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 0, 1},
  {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1},
  {&__pyx_kp_s_c_2, __pyx_k_c_2, sizeof(__pyx_k_c_2), 0, 0, 1, 0},
  {&__pyx_n_s_calcsize, __pyx_k_calcsize, sizeof(__pyx_k_calcsize), 0, 0, 1, 1},
  {&__pyx_n_s_callback, __pyx_k_callback, sizeof(__pyx_k_callback), 0, 0, 1, 1},
  {&__pyx_kp_s_callback_not_implemented_yet, __pyx_k_callback_not_implemented_yet, sizeof(__pyx_k_callback_not_implemented_yet), 0, 0, 1, 0},
  {&__pyx_kp_s_can_not_iterate_over_samfile_wit, __pyx_k_can_not_iterate_over_samfile_wit, sizeof(__pyx_k_can_not_iterate_over_samfile_wit), 0, 0, 1, 0},
  {&__pyx_kp_s_can_only_IndexReads_on_bam_files, __pyx_k_can_only_IndexReads_on_bam_files, sizeof(__pyx_k_can_only_IndexReads_on_bam_files), 0, 0, 1, 0},
  {&__pyx_kp_s_can_t_guess_type_or_invalid_type, __pyx_k_can_t_guess_type_or_invalid_type, sizeof(__pyx_k_can_t_guess_type_or_invalid_type), 0, 0, 1, 0},
  {&__pyx_n_s_checkIndex, __pyx_k_checkIndex, sizeof(__pyx_k_checkIndex), 0, 0, 1, 1},
  {&__pyx_n_s_check_header, __pyx_k_check_header, sizeof(__pyx_k_check_header), 0, 0, 1, 1},
  {&__pyx_n_s_check_sq, __pyx_k_check_sq, sizeof(__pyx_k_check_sq), 0, 0, 1, 1},
  {&__pyx_n_s_chr, __pyx_k_chr, sizeof(__pyx_k_chr), 0, 0, 1, 1},
  {&__pyx_n_s_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_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1},
  {&__pyx_n_s_compare, __pyx_k_compare, sizeof(__pyx_k_compare), 0, 0, 1, 1},
  {&__pyx_n_s_compile, __pyx_k_compile, sizeof(__pyx_k_compile), 0, 0, 1, 1},
  {&__pyx_n_s_consensus_quality, __pyx_k_consensus_quality, sizeof(__pyx_k_consensus_quality), 0, 0, 1, 1},
  {&__pyx_kp_s_could_not_open_file_mode_s_is_it, __pyx_k_could_not_open_file_mode_s_is_it, sizeof(__pyx_k_could_not_open_file_mode_s_is_it), 0, 0, 1, 0},
  {&__pyx_kp_s_could_not_open_file_s, __pyx_k_could_not_open_file_s, sizeof(__pyx_k_could_not_open_file_s), 0, 0, 1, 0},
  {&__pyx_n_s_coverage, __pyx_k_coverage, sizeof(__pyx_k_coverage), 0, 0, 1, 1},
  {&__pyx_kp_b_crai, __pyx_k_crai, sizeof(__pyx_k_crai), 0, 0, 0, 0},
  {&__pyx_n_s_create_string_buffer, __pyx_k_create_string_buffer, sizeof(__pyx_k_create_string_buffer), 0, 0, 1, 1},
  {&__pyx_n_s_ctypes, __pyx_k_ctypes, sizeof(__pyx_k_ctypes), 0, 0, 1, 1},
  {&__pyx_n_s_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 1, 1},
  {&__pyx_kp_s_d_MIDNSHP_X, __pyx_k_d_MIDNSHP_X, sizeof(__pyx_k_d_MIDNSHP_X), 0, 0, 1, 0},
  {&__pyx_n_s_decode, __pyx_k_decode, sizeof(__pyx_k_decode), 0, 0, 1, 1},
  {&__pyx_n_s_defaultdict, __pyx_k_defaultdict, sizeof(__pyx_k_defaultdict), 0, 0, 1, 1},
  {&__pyx_kp_s_either_supply_options_template_h, __pyx_k_either_supply_options_template_h, sizeof(__pyx_k_either_supply_options_template_h), 0, 0, 1, 0},
  {&__pyx_n_s_encode, __pyx_k_encode, sizeof(__pyx_k_encode), 0, 0, 1, 1},
  {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1},
  {&__pyx_kp_s_end_out_of_range_i, __pyx_k_end_out_of_range_i, sizeof(__pyx_k_end_out_of_range_i), 0, 0, 1, 0},
  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
  {&__pyx_kp_s_error_during_iteration, __pyx_k_error_during_iteration, sizeof(__pyx_k_error_during_iteration), 0, 0, 1, 0},
  {&__pyx_kp_s_error_while_opening_index_for_s, __pyx_k_error_while_opening_index_for_s, sizeof(__pyx_k_error_while_opening_index_for_s), 0, 0, 1, 0},
  {&__pyx_n_s_exc_type, __pyx_k_exc_type, sizeof(__pyx_k_exc_type), 0, 0, 1, 1},
  {&__pyx_n_s_exc_value, __pyx_k_exc_value, sizeof(__pyx_k_exc_value), 0, 0, 1, 1},
  {&__pyx_n_s_exists, __pyx_k_exists, sizeof(__pyx_k_exists), 0, 0, 1, 1},
  {&__pyx_n_b_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 0, 1},
  {&__pyx_n_s_f, __pyx_k_f, sizeof(__pyx_k_f), 0, 0, 1, 1},
  {&__pyx_n_s_fastafile, __pyx_k_fastafile, sizeof(__pyx_k_fastafile), 0, 0, 1, 1},
  {&__pyx_n_s_fetch, __pyx_k_fetch, sizeof(__pyx_k_fetch), 0, 0, 1, 1},
  {&__pyx_kp_s_fetch_called_for_htsfile_without, __pyx_k_fetch_called_for_htsfile_without, sizeof(__pyx_k_fetch_called_for_htsfile_without), 0, 0, 1, 0},
  {&__pyx_kp_s_fetch_called_on_bamfile_without, __pyx_k_fetch_called_on_bamfile_without, sizeof(__pyx_k_fetch_called_on_bamfile_without), 0, 0, 1, 0},
  {&__pyx_kp_s_fetching_by_region_is_not_availa, __pyx_k_fetching_by_region_is_not_availa, sizeof(__pyx_k_fetching_by_region_is_not_availa), 0, 0, 1, 0},
  {&__pyx_n_s_fields, __pyx_k_fields, sizeof(__pyx_k_fields), 0, 0, 1, 1},
  {&__pyx_kp_s_file_does_not_have_valid_header, __pyx_k_file_does_not_have_valid_header, sizeof(__pyx_k_file_does_not_have_valid_header), 0, 0, 1, 0},
  {&__pyx_kp_s_file_does_not_have_valid_header_2, __pyx_k_file_does_not_have_valid_header_2, sizeof(__pyx_k_file_does_not_have_valid_header_2), 0, 0, 1, 0},
  {&__pyx_kp_s_file_header_is_empty_mode_s_is_i, __pyx_k_file_header_is_empty_mode_s_is_i, sizeof(__pyx_k_file_header_is_empty_mode_s_is_i), 0, 0, 1, 0},
  {&__pyx_kp_s_file_s_not_found, __pyx_k_file_s_not_found, sizeof(__pyx_k_file_s_not_found), 0, 0, 1, 0},
  {&__pyx_n_s_filename, __pyx_k_filename, sizeof(__pyx_k_filename), 0, 0, 1, 1},
  {&__pyx_n_s_findall, __pyx_k_findall, sizeof(__pyx_k_findall), 0, 0, 1, 1},
  {&__pyx_n_s_flag, __pyx_k_flag, sizeof(__pyx_k_flag), 0, 0, 1, 1},
  {&__pyx_n_s_fromQualityString, __pyx_k_fromQualityString, sizeof(__pyx_k_fromQualityString), 0, 0, 1, 1},
  {&__pyx_kp_b_ftp, __pyx_k_ftp, sizeof(__pyx_k_ftp), 0, 0, 0, 0},
  {&__pyx_n_s_full_length, __pyx_k_full_length, sizeof(__pyx_k_full_length), 0, 0, 1, 1},
  {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 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_blocks, __pyx_k_get_blocks, sizeof(__pyx_k_get_blocks), 0, 0, 1, 1},
  {&__pyx_n_s_get_overlap, __pyx_k_get_overlap, sizeof(__pyx_k_get_overlap), 0, 0, 1, 1},
  {&__pyx_n_s_get_reference_positions, __pyx_k_get_reference_positions, sizeof(__pyx_k_get_reference_positions), 0, 0, 1, 1},
  {&__pyx_n_s_get_tag, __pyx_k_get_tag, sizeof(__pyx_k_get_tag), 0, 0, 1, 1},
  {&__pyx_n_s_get_tags, __pyx_k_get_tags, sizeof(__pyx_k_get_tags), 0, 0, 1, 1},
  {&__pyx_n_s_get_verbosity, __pyx_k_get_verbosity, sizeof(__pyx_k_get_verbosity), 0, 0, 1, 1},
  {&__pyx_n_s_getdefaultencoding, __pyx_k_getdefaultencoding, sizeof(__pyx_k_getdefaultencoding), 0, 0, 1, 1},
  {&__pyx_n_s_getfilesystemencoding, __pyx_k_getfilesystemencoding, sizeof(__pyx_k_getfilesystemencoding), 0, 0, 1, 1},
  {&__pyx_n_s_gettid, __pyx_k_gettid, sizeof(__pyx_k_gettid), 0, 0, 1, 1},
  {&__pyx_n_s_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 0, 1, 1},
  {&__pyx_n_s_hasIndex, __pyx_k_hasIndex, sizeof(__pyx_k_hasIndex), 0, 0, 1, 1},
  {&__pyx_n_s_has_tag, __pyx_k_has_tag, sizeof(__pyx_k_has_tag), 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_b_http, __pyx_k_http, sizeof(__pyx_k_http), 0, 0, 0, 0},
  {&__pyx_n_b_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 0, 1},
  {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
  {&__pyx_kp_s_i_c, __pyx_k_i_c, sizeof(__pyx_k_i_c), 0, 0, 1, 0},
  {&__pyx_kp_s_ifs_devel_andreas_pysam_pysam_c, __pyx_k_ifs_devel_andreas_pysam_pysam_c, sizeof(__pyx_k_ifs_devel_andreas_pysam_pysam_c), 0, 0, 1, 0},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_kp_s_incomplete_sequence_information, __pyx_k_incomplete_sequence_information, sizeof(__pyx_k_incomplete_sequence_information), 0, 0, 1, 0},
  {&__pyx_n_s_indel, __pyx_k_indel, sizeof(__pyx_k_indel), 0, 0, 1, 1},
  {&__pyx_n_s_infer_query_length, __pyx_k_infer_query_length, sizeof(__pyx_k_infer_query_length), 0, 0, 1, 1},
  {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1},
  {&__pyx_kp_s_invalid_coordinates_start_i_end, __pyx_k_invalid_coordinates_start_i_end, sizeof(__pyx_k_invalid_coordinates_start_i_end), 0, 0, 1, 0},
  {&__pyx_kp_s_invalid_file_opening_mode_s, __pyx_k_invalid_file_opening_mode_s, sizeof(__pyx_k_invalid_file_opening_mode_s), 0, 0, 1, 0},
  {&__pyx_kp_s_invalid_reference_s, __pyx_k_invalid_reference_s, sizeof(__pyx_k_invalid_reference_s), 0, 0, 1, 0},
  {&__pyx_kp_s_invalid_type_for_record_s_s_expe, __pyx_k_invalid_type_for_record_s_s_expe, sizeof(__pyx_k_invalid_type_for_record_s_s_expe), 0, 0, 1, 0},
  {&__pyx_kp_s_invalid_value_type_s, __pyx_k_invalid_value_type_s, sizeof(__pyx_k_invalid_value_type_s), 0, 0, 1, 0},
  {&__pyx_n_s_isOpen, __pyx_k_isOpen, sizeof(__pyx_k_isOpen), 0, 0, 1, 1},
  {&__pyx_n_s_is_del, __pyx_k_is_del, sizeof(__pyx_k_is_del), 0, 0, 1, 1},
  {&__pyx_n_s_is_head, __pyx_k_is_head, sizeof(__pyx_k_is_head), 0, 0, 1, 1},
  {&__pyx_n_s_is_refskip, __pyx_k_is_refskip, sizeof(__pyx_k_is_refskip), 0, 0, 1, 1},
  {&__pyx_n_s_is_tail, __pyx_k_is_tail, sizeof(__pyx_k_is_tail), 0, 0, 1, 1},
  {&__pyx_n_s_islower, __pyx_k_islower, sizeof(__pyx_k_islower), 0, 0, 1, 1},
  {&__pyx_n_s_isupper, __pyx_k_isupper, sizeof(__pyx_k_isupper), 0, 0, 1, 1},
  {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
  {&__pyx_n_s_itertools, __pyx_k_itertools, sizeof(__pyx_k_itertools), 0, 0, 1, 1},
  {&__pyx_n_s_join, __pyx_k_join, sizeof(__pyx_k_join), 0, 0, 1, 1},
  {&__pyx_n_s_lengths, __pyx_k_lengths, sizeof(__pyx_k_lengths), 0, 0, 1, 1},
  {&__pyx_n_s_level, __pyx_k_level, sizeof(__pyx_k_level), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_kp_s_malformatted_header_no_in_field, __pyx_k_malformatted_header_no_in_field, sizeof(__pyx_k_malformatted_header_no_in_field), 0, 0, 1, 0},
  {&__pyx_kp_s_malformatted_tag_s, __pyx_k_malformatted_tag_s, sizeof(__pyx_k_malformatted_tag_s), 0, 0, 1, 0},
  {&__pyx_n_s_map, __pyx_k_map, sizeof(__pyx_k_map), 0, 0, 1, 1},
  {&__pyx_kp_s_mapping_information_not_recorded, __pyx_k_mapping_information_not_recorded, sizeof(__pyx_k_mapping_information_not_recorded), 0, 0, 1, 0},
  {&__pyx_n_s_mapping_quality, __pyx_k_mapping_quality, sizeof(__pyx_k_mapping_quality), 0, 0, 1, 1},
  {&__pyx_n_s_matches_only, __pyx_k_matches_only, sizeof(__pyx_k_matches_only), 0, 0, 1, 1},
  {&__pyx_kp_s_mate_not_found, __pyx_k_mate_not_found, sizeof(__pyx_k_mate_not_found), 0, 0, 1, 0},
  {&__pyx_kp_s_mate_s_is_unmapped, __pyx_k_mate_s_is_unmapped, sizeof(__pyx_k_mate_s_is_unmapped), 0, 0, 1, 0},
  {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1},
  {&__pyx_n_s_max_depth, __pyx_k_max_depth, sizeof(__pyx_k_max_depth), 0, 0, 1, 1},
  {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1},
  {&__pyx_n_s_mode, __pyx_k_mode, sizeof(__pyx_k_mode), 0, 0, 1, 1},
  {&__pyx_n_s_multiple_iterators, __pyx_k_multiple_iterators, sizeof(__pyx_k_multiple_iterators), 0, 0, 1, 1},
  {&__pyx_kp_s_multiple_s_lines_are_not_permitt, __pyx_k_multiple_s_lines_are_not_permitt, sizeof(__pyx_k_multiple_s_lines_are_not_permitt), 0, 0, 1, 0},
  {&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1},
  {&__pyx_n_s_next_reference_id, __pyx_k_next_reference_id, sizeof(__pyx_k_next_reference_id), 0, 0, 1, 1},
  {&__pyx_n_s_next_reference_start, __pyx_k_next_reference_start, sizeof(__pyx_k_next_reference_start), 0, 0, 1, 1},
  {&__pyx_n_s_nextiter, __pyx_k_nextiter, sizeof(__pyx_k_nextiter), 0, 0, 1, 1},
  {&__pyx_kp_s_no_index_available_for_fetch, __pyx_k_no_index_available_for_fetch, sizeof(__pyx_k_no_index_available_for_fetch), 0, 0, 1, 0},
  {&__pyx_kp_s_no_index_available_for_iteration, __pyx_k_no_index_available_for_iteration, sizeof(__pyx_k_no_index_available_for_iteration), 0, 0, 1, 0},
  {&__pyx_kp_s_no_index_available_for_pileup, __pyx_k_no_index_available_for_pileup, sizeof(__pyx_k_no_index_available_for_pileup), 0, 0, 1, 0},
  {&__pyx_n_s_nofilter, __pyx_k_nofilter, sizeof(__pyx_k_nofilter), 0, 0, 1, 1},
  {&__pyx_n_s_nreferences, __pyx_k_nreferences, sizeof(__pyx_k_nreferences), 0, 0, 1, 1},
  {&__pyx_n_s_nsegments, __pyx_k_nsegments, sizeof(__pyx_k_nsegments), 0, 0, 1, 1},
  {&__pyx_n_s_offset, __pyx_k_offset, sizeof(__pyx_k_offset), 0, 0, 1, 1},
  {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1},
  {&__pyx_n_s_ord, __pyx_k_ord, sizeof(__pyx_k_ord), 0, 0, 1, 1},
  {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1},
  {&__pyx_n_s_pack_into, __pyx_k_pack_into, sizeof(__pyx_k_pack_into), 0, 0, 1, 1},
  {&__pyx_n_s_parseRegion, __pyx_k_parseRegion, sizeof(__pyx_k_parseRegion), 0, 0, 1, 1},
  {&__pyx_n_s_path, __pyx_k_path, sizeof(__pyx_k_path), 0, 0, 1, 1},
  {&__pyx_kp_s_pileup_of_samfiles_not_implement, __pyx_k_pileup_of_samfiles_not_implement, sizeof(__pyx_k_pileup_of_samfiles_not_implement), 0, 0, 1, 0},
  {&__pyx_n_s_pileups, __pyx_k_pileups, sizeof(__pyx_k_pileups), 0, 0, 1, 1},
  {&__pyx_n_s_platform, __pyx_k_platform, sizeof(__pyx_k_platform), 0, 0, 1, 1},
  {&__pyx_n_s_port, __pyx_k_port, sizeof(__pyx_k_port), 0, 0, 1, 1},
  {&__pyx_n_s_pos, __pyx_k_pos, sizeof(__pyx_k_pos), 0, 0, 1, 1},
  {&__pyx_n_s_positions, __pyx_k_positions, sizeof(__pyx_k_positions), 0, 0, 1, 1},
  {&__pyx_n_s_pysam_calignmentfile, __pyx_k_pysam_calignmentfile, sizeof(__pyx_k_pysam_calignmentfile), 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_qualities, __pyx_k_qualities, sizeof(__pyx_k_qualities), 0, 0, 1, 1},
  {&__pyx_kp_s_quality_and_sequence_mismatch_i, __pyx_k_quality_and_sequence_mismatch_i, sizeof(__pyx_k_quality_and_sequence_mismatch_i), 0, 0, 1, 0},
  {&__pyx_n_s_quality_string, __pyx_k_quality_string, sizeof(__pyx_k_quality_string), 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_alignment_end, __pyx_k_query_alignment_end, sizeof(__pyx_k_query_alignment_end), 0, 0, 1, 1},
  {&__pyx_n_s_query_alignment_length, __pyx_k_query_alignment_length, sizeof(__pyx_k_query_alignment_length), 0, 0, 1, 1},
  {&__pyx_n_s_query_alignment_qualities, __pyx_k_query_alignment_qualities, sizeof(__pyx_k_query_alignment_qualities), 0, 0, 1, 1},
  {&__pyx_n_s_query_alignment_sequence, __pyx_k_query_alignment_sequence, sizeof(__pyx_k_query_alignment_sequence), 0, 0, 1, 1},
  {&__pyx_n_s_query_alignment_start, __pyx_k_query_alignment_start, sizeof(__pyx_k_query_alignment_start), 0, 0, 1, 1},
  {&__pyx_n_s_query_length, __pyx_k_query_length, sizeof(__pyx_k_query_length), 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_position, __pyx_k_query_position, sizeof(__pyx_k_query_position), 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_query_sequence, __pyx_k_query_sequence, sizeof(__pyx_k_query_sequence), 0, 0, 1, 1},
  {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1},
  {&__pyx_n_s_rU, __pyx_k_rU, sizeof(__pyx_k_rU), 0, 0, 1, 1},
  {&__pyx_n_s_raw, __pyx_k_raw, sizeof(__pyx_k_raw), 0, 0, 1, 1},
  {&__pyx_n_s_rb, __pyx_k_rb, sizeof(__pyx_k_rb), 0, 0, 1, 1},
  {&__pyx_n_s_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_kp_s_read_s_is_unpaired, __pyx_k_read_s_is_unpaired, sizeof(__pyx_k_read_s_is_unpaired), 0, 0, 1, 0},
  {&__pyx_kp_s_read_s_not_found, __pyx_k_read_s_not_found, sizeof(__pyx_k_read_s_not_found), 0, 0, 1, 0},
  {&__pyx_n_s_record, __pyx_k_record, sizeof(__pyx_k_record), 0, 0, 1, 1},
  {&__pyx_n_s_reference, __pyx_k_reference, sizeof(__pyx_k_reference), 0, 0, 1, 1},
  {&__pyx_n_s_reference_base, __pyx_k_reference_base, sizeof(__pyx_k_reference_base), 0, 0, 1, 1},
  {&__pyx_n_s_reference_end, __pyx_k_reference_end, sizeof(__pyx_k_reference_end), 0, 0, 1, 1},
  {&__pyx_n_s_reference_filename, __pyx_k_reference_filename, sizeof(__pyx_k_reference_filename), 0, 0, 1, 1},
  {&__pyx_n_s_reference_id, __pyx_k_reference_id, sizeof(__pyx_k_reference_id), 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_length, __pyx_k_reference_length, sizeof(__pyx_k_reference_length), 0, 0, 1, 1},
  {&__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_n_s_reference_pos, __pyx_k_reference_pos, sizeof(__pyx_k_reference_pos), 0, 0, 1, 1},
  {&__pyx_kp_s_reference_sequence_for_s_tid_i_n, __pyx_k_reference_sequence_for_s_tid_i_n, sizeof(__pyx_k_reference_sequence_for_s_tid_i_n), 0, 0, 1, 0},
  {&__pyx_n_s_reference_start, __pyx_k_reference_start, sizeof(__pyx_k_reference_start), 0, 0, 1, 1},
  {&__pyx_n_s_referencelengths, __pyx_k_referencelengths, sizeof(__pyx_k_referencelengths), 0, 0, 1, 1},
  {&__pyx_n_s_referencenames, __pyx_k_referencenames, sizeof(__pyx_k_referencenames), 0, 0, 1, 1},
  {&__pyx_n_s_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_replace, __pyx_k_replace, sizeof(__pyx_k_replace), 0, 0, 1, 1},
  {&__pyx_kp_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 0},
  {&__pyx_n_b_s_2, __pyx_k_s_2, sizeof(__pyx_k_s_2), 0, 0, 0, 1},
  {&__pyx_n_s_s_2, __pyx_k_s_2, sizeof(__pyx_k_s_2), 0, 0, 1, 1},
  {&__pyx_kp_s_s_s, __pyx_k_s_s, sizeof(__pyx_k_s_s), 0, 0, 1, 0},
  {&__pyx_kp_s_sam_write_failed, __pyx_k_sam_write_failed, sizeof(__pyx_k_sam_write_failed), 0, 0, 1, 0},
  {&__pyx_n_s_samfile, __pyx_k_samfile, sizeof(__pyx_k_samfile), 0, 0, 1, 1},
  {&__pyx_n_s_samtools, __pyx_k_samtools, sizeof(__pyx_k_samtools), 0, 0, 1, 1},
  {&__pyx_n_s_seek, __pyx_k_seek, sizeof(__pyx_k_seek), 0, 0, 1, 1},
  {&__pyx_kp_s_seek_no_available_in_streams, __pyx_k_seek_no_available_in_streams, sizeof(__pyx_k_seek_no_available_in_streams), 0, 0, 1, 0},
  {&__pyx_kp_s_seek_only_available_in_bam_files, __pyx_k_seek_only_available_in_bam_files, sizeof(__pyx_k_seek_only_available_in_bam_files), 0, 0, 1, 0},
  {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1},
  {&__pyx_n_s_seq, __pyx_k_seq, sizeof(__pyx_k_seq), 0, 0, 1, 1},
  {&__pyx_n_s_set_tag, __pyx_k_set_tag, sizeof(__pyx_k_set_tag), 0, 0, 1, 1},
  {&__pyx_n_s_set_tags, __pyx_k_set_tags, sizeof(__pyx_k_set_tags), 0, 0, 1, 1},
  {&__pyx_n_s_set_verbosity, __pyx_k_set_verbosity, sizeof(__pyx_k_set_verbosity), 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_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1},
  {&__pyx_kp_s_start_out_of_range_i, __pyx_k_start_out_of_range_i, sizeof(__pyx_k_start_out_of_range_i), 0, 0, 1, 0},
  {&__pyx_n_s_startswith, __pyx_k_startswith, sizeof(__pyx_k_startswith), 0, 0, 1, 1},
  {&__pyx_n_s_stepper, __pyx_k_stepper, sizeof(__pyx_k_stepper), 0, 0, 1, 1},
  {&__pyx_n_s_stop, __pyx_k_stop, sizeof(__pyx_k_stop), 0, 0, 1, 1},
  {&__pyx_n_s_strip, __pyx_k_strip, sizeof(__pyx_k_strip), 0, 0, 1, 1},
  {&__pyx_n_s_struct, __pyx_k_struct, sizeof(__pyx_k_struct), 0, 0, 1, 1},
  {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1},
  {&__pyx_n_s_tag, __pyx_k_tag, sizeof(__pyx_k_tag), 0, 0, 1, 1},
  {&__pyx_kp_s_tag_s_not_present, __pyx_k_tag_s_not_present, sizeof(__pyx_k_tag_s_not_present), 0, 0, 1, 0},
  {&__pyx_n_s_tags, __pyx_k_tags, sizeof(__pyx_k_tags), 0, 0, 1, 1},
  {&__pyx_n_s_tell, __pyx_k_tell, sizeof(__pyx_k_tell), 0, 0, 1, 1},
  {&__pyx_n_s_tempfile, __pyx_k_tempfile, sizeof(__pyx_k_tempfile), 0, 0, 1, 1},
  {&__pyx_n_s_template, __pyx_k_template, sizeof(__pyx_k_template), 0, 0, 1, 1},
  {&__pyx_n_s_template_length, __pyx_k_template_length, sizeof(__pyx_k_template_length), 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_kp_s_this_class_cannot_be_instantiate, __pyx_k_this_class_cannot_be_instantiate, sizeof(__pyx_k_this_class_cannot_be_instantiate), 0, 0, 1, 0},
  {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1},
  {&__pyx_n_s_tid, __pyx_k_tid, sizeof(__pyx_k_tid), 0, 0, 1, 1},
  {&__pyx_kp_s_tid_i_out_of_range_0_tid_i, __pyx_k_tid_i_out_of_range_0_tid_i, sizeof(__pyx_k_tid_i_out_of_range_0_tid_i), 0, 0, 1, 0},
  {&__pyx_n_s_toQualityString, __pyx_k_toQualityString, sizeof(__pyx_k_toQualityString), 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_n_s_types, __pyx_k_types, sizeof(__pyx_k_types), 0, 0, 1, 1},
  {&__pyx_kp_s_unable_to_open_remote_index_for, __pyx_k_unable_to_open_remote_index_for, sizeof(__pyx_k_unable_to_open_remote_index_for), 0, 0, 1, 0},
  {&__pyx_kp_s_unequal_names_and_lengths_of_ref, __pyx_k_unequal_names_and_lengths_of_ref, sizeof(__pyx_k_unequal_names_and_lengths_of_ref), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_auxilliary_type_s, __pyx_k_unknown_auxilliary_type_s, sizeof(__pyx_k_unknown_auxilliary_type_s), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_field_code_s_in_record_s, __pyx_k_unknown_field_code_s_in_record_s, sizeof(__pyx_k_unknown_field_code_s_in_record_s), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_stepper_option_s_in_Iter, __pyx_k_unknown_stepper_option_s_in_Iter, sizeof(__pyx_k_unknown_stepper_option_s_in_Iter), 0, 0, 1, 0},
  {&__pyx_kp_s_unknown_type_s, __pyx_k_unknown_type_s, sizeof(__pyx_k_unknown_type_s), 0, 0, 1, 0},
  {&__pyx_n_s_until_eof, __pyx_k_until_eof, sizeof(__pyx_k_until_eof), 0, 0, 1, 1},
  {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1},
  {&__pyx_n_s_value_type, __pyx_k_value_type, sizeof(__pyx_k_value_type), 0, 0, 1, 1},
  {&__pyx_n_s_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_where, __pyx_k_where, sizeof(__pyx_k_where), 0, 0, 1, 1},
  {&__pyx_n_s_with_value_type, __pyx_k_with_value_type, sizeof(__pyx_k_with_value_type), 0, 0, 1, 1},
  {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1},
  {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1},
  {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ord = __Pyx_GetBuiltinName(__pyx_n_s_ord); if (!__pyx_builtin_ord) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 364; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_IOError = __Pyx_GetBuiltinName(__pyx_n_s_IOError); if (!__pyx_builtin_IOError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_OverflowError = __Pyx_GetBuiltinName(__pyx_n_s_OverflowError); if (!__pyx_builtin_OverflowError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 614; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_n_s_NotImplementedError); if (!__pyx_builtin_NotImplementedError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_OSError = __Pyx_GetBuiltinName(__pyx_n_s_OSError); if (!__pyx_builtin_OSError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1282; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1366; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_StopIteration = __Pyx_GetBuiltinName(__pyx_n_s_StopIteration); if (!__pyx_builtin_StopIteration) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1422; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_chr = __Pyx_GetBuiltinName(__pyx_n_s_chr); if (!__pyx_builtin_chr) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2209; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_min = __Pyx_GetBuiltinName(__pyx_n_s_min); if (!__pyx_builtin_min) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2339; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_map = __Pyx_GetBuiltinName(__pyx_n_s_map); if (!__pyx_builtin_map) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_NotImplemented = __Pyx_GetBuiltinName(__pyx_n_s_NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "pysam/calignmentfile.pyx":73
 *         return s
 *     elif PyUnicode_Check(s):
 *         return s.encode('ascii')             # <<<<<<<<<<<<<<
 *     else:
 *         raise TypeError, u"Argument must be string, bytes or unicode."
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "pysam/calignmentfile.pyx":94
 *         return s
 *     elif PyBytes_Check(s):
 *         return s.decode('ascii')             # <<<<<<<<<<<<<<
 *     else:
 *         # assume unicode
 */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "pysam/calignmentfile.pyx":392
 *             mode = "wb0"
 * 
 *         cdef bytes bmode = mode.encode('ascii')             # <<<<<<<<<<<<<<
 *         self._filename = filename = _encodeFilename(filename)
 * 
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "pysam/calignmentfile.pyx":399
 *         self.is_cram = len(mode) > 1 and mode[1] == 'c'
 *         self.is_stream = filename == b"-"
 *         self.is_remote = filename.startswith(b"http:") or \             # <<<<<<<<<<<<<<
 *                          filename.startswith(b"ftp:")
 * 
 */
  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_b_http); if (unlikely(!__pyx_tuple__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);

  /* "pysam/calignmentfile.pyx":400
 *         self.is_stream = filename == b"-"
 *         self.is_remote = filename.startswith(b"http:") or \
 *                          filename.startswith(b"ftp:")             # <<<<<<<<<<<<<<
 * 
 *         cdef char * ctext
 */
  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_b_ftp); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "pysam/calignmentfile.pyx":535
 *                 if self.is_bam \
 *                    and not os.path.exists(filename + b".bai") \
 *                    and not os.path.exists(filename[:-4] + b".bai"):             # <<<<<<<<<<<<<<
 *                     self.index = NULL
 *                 elif self.is_cram \
 */
  __pyx_slice__8 = PySlice_New(Py_None, __pyx_int_neg_4, Py_None); if (unlikely(!__pyx_slice__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 535; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__8);
  __Pyx_GIVEREF(__pyx_slice__8);

  /* "pysam/calignmentfile.pyx":539
 *                 elif self.is_cram \
 *                      and not os.path.exists(filename + b".crai") \
 *                      and not os.path.exists(filename[:-4] + b".crai"):             # <<<<<<<<<<<<<<
 *                     self.index = NULL
 *                 else:
 */
  __pyx_slice__9 = PySlice_New(Py_None, __pyx_int_neg_4, Py_None); if (unlikely(!__pyx_slice__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__9);
  __Pyx_GIVEREF(__pyx_slice__9);

  /* "pysam/calignmentfile.pyx":562
 *         '''
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         reference = _forceBytes(reference)
 *         return bam_name2id(self.header, reference)
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "pysam/calignmentfile.pyx":570
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not 0 <= tid < self.header.n_targets:
 *             raise ValueError("reference_id %i out of range 0<=tid<%i" %
 */
  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);

  /* "pysam/calignmentfile.pyx":580
 *         convert numerical :term:`tid` into :term:`reference` name.'''
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         if not 0 <= tid < self.header.n_targets:
 */
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "pysam/calignmentfile.pyx":633
 * 
 *         if not reference:
 *             return 0, 0, 0, 0             # <<<<<<<<<<<<<<
 * 
 *         if tid is not None:
 */
  __pyx_tuple__14 = PyTuple_Pack(4, __pyx_int_0, __pyx_int_0, __pyx_int_0, __pyx_int_0); if (unlikely(!__pyx_tuple__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);

  /* "pysam/calignmentfile.pyx":664
 * 
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not self.is_bam:
 *             raise NotImplementedError(
 */
  __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 664; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);

  /* "pysam/calignmentfile.pyx":666
 *             raise ValueError("I/O operation on closed file")
 *         if not self.is_bam:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "seek only available in bam files")
 *         if self.is_stream:
 */
  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_s_seek_only_available_in_bam_files); if (unlikely(!__pyx_tuple__16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);

  /* "pysam/calignmentfile.pyx":669
 *                 "seek only available in bam files")
 *         if self.is_stream:
 *             raise OSError("seek no available in streams")             # <<<<<<<<<<<<<<
 * 
 *         return bgzf_seek(hts_get_bgzfp(self.htsfile), offset, where)
 */
  __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_s_seek_no_available_in_streams); if (unlikely(!__pyx_tuple__17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__17);
  __Pyx_GIVEREF(__pyx_tuple__17);

  /* "pysam/calignmentfile.pyx":678
 *         '''
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not (self.is_bam or self.is_cram):
 *             raise NotImplementedError(
 */
  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);

  /* "pysam/calignmentfile.pyx":680
 *             raise ValueError("I/O operation on closed file")
 *         if not (self.is_bam or self.is_cram):
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "seek only available in bam files")
 * 
 */
  __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_s_seek_only_available_in_bam_files); if (unlikely(!__pyx_tuple__19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__19);
  __Pyx_GIVEREF(__pyx_tuple__19);

  /* "pysam/calignmentfile.pyx":725
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(reference,
 */
  __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);

  /* "pysam/calignmentfile.pyx":740
 *             if not until_eof and not self.is_remote:
 *                 if not self._hasIndex():
 *                     raise ValueError(             # <<<<<<<<<<<<<<
 *                         "fetch called on bamfile without index")
 * 
 */
  __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s_fetch_called_on_bamfile_without); if (unlikely(!__pyx_tuple__21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 740; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "pysam/calignmentfile.pyx":760
 *         else:
 *             if has_coord:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "fetching by region is not available for sam files")
 * 
 */
  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s_fetching_by_region_is_not_availa); if (unlikely(!__pyx_tuple__22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "pysam/calignmentfile.pyx":764
 * 
 *             if callback:
 *                 raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                     "callback not implemented yet")
 * 
 */
  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_s_callback_not_implemented_yet); if (unlikely(!__pyx_tuple__23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 764; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "pysam/calignmentfile.pyx":768
 * 
 *             if self.header == NULL:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "fetch called for htsfile without header")
 * 
 */
  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_fetch_called_for_htsfile_without); if (unlikely(!__pyx_tuple__24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "pysam/calignmentfile.pyx":774
 *             # give warning, sam_read1 segfaults
 *             if self.header.n_targets == 0:
 *                 warnings.warn("fetch called for htsfile without header")             # <<<<<<<<<<<<<<
 * 
 *             return IteratorRowAll(self,
 */
  __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_s_fetch_called_for_htsfile_without); if (unlikely(!__pyx_tuple__25)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);

  /* "pysam/calignmentfile.pyx":838
 *                 break
 *         else:
 *             raise ValueError("mate not found")             # <<<<<<<<<<<<<<
 * 
 *         return mate
 */
  __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_mate_not_found); if (unlikely(!__pyx_tuple__26)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);

  /* "pysam/calignmentfile.pyx":863
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         for read in self.fetch(reference=reference,
 */
  __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);

  /* "pysam/calignmentfile.pyx":946
 * 
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         has_coord, rtid, rstart, rend = self._parseRegion(
 */
  __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__28)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);

  /* "pysam/calignmentfile.pyx":953
 *         if self.is_bam or self.is_cram:
 *             if not self._hasIndex():
 *                 raise ValueError("no index available for pileup")             # <<<<<<<<<<<<<<
 * 
 *             if has_coord:
 */
  __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_pileup); if (unlikely(!__pyx_tuple__29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "pysam/calignmentfile.pyx":965
 * 
 *         else:
 *             raise NotImplementedError( "pileup of samfiles not implemented yet" )             # <<<<<<<<<<<<<<
 * 
 *     @cython.boundscheck(False)  # we do manual bounds checking
 */
  __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s_pileup_of_samfiles_not_implement); if (unlikely(!__pyx_tuple__30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 965; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);

  /* "pysam/calignmentfile.pyx":1022
 *             seq = read.seq
 *             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:
 *                     if quality[qpos] > quality_threshold:
 */
  __pyx_tuple__31 = PyTuple_Pack(1, Py_True); if (unlikely(!__pyx_tuple__31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1022; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);

  /* "pysam/calignmentfile.pyx":1075
 *         #      exception set".
 *         if ret < 0:
 *             raise ValueError('sam write failed')             # <<<<<<<<<<<<<<
 * 
 *         return ret
 */
  __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_sam_write_failed); if (unlikely(!__pyx_tuple__32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "pysam/calignmentfile.pyx":1099
 *         '''number of :term:`reference` sequences in the file.'''
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             return self.header.n_targets
 * 
 */
  __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);

  /* "pysam/calignmentfile.pyx":1105
 *         """tuple with the names of :term:`reference` sequences."""
 *         def __get__(self):
 *             if not self._isOpen(): raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             t = []
 *             for x from 0 <= x < self.header.n_targets:
 */
  __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__34)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);

  /* "pysam/calignmentfile.pyx":1119
 *         def __get__(self):
 *             if not self._isOpen():
 *                 raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *             t = []
 *             for x from 0 <= x < self.header.n_targets:
 */
  __pyx_tuple__35 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);

  /* "pysam/calignmentfile.pyx":1143
 *         an error.'''
 *         if not self._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 *         if not self.is_bam and not self.is_cram:
 *             raise AttributeError(
 */
  __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__36)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1143; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "pysam/calignmentfile.pyx":1145
 *             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__37 = PyTuple_Pack(1, __pyx_kp_s_AlignmentFile_mapped_only_availa); if (unlikely(!__pyx_tuple__37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);

  /* "pysam/calignmentfile.pyx":1148
 *                 "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__38 = PyTuple_Pack(1, __pyx_kp_s_mapping_information_not_recorded); if (unlikely(!__pyx_tuple__38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1148; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);

  /* "pysam/calignmentfile.pyx":1184
 *         def __get__(self):
 *             if not self._isOpen():
 *                 raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 *             return from_string_and_size(self.header.text, self.header.l_text)
 * 
 */
  __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__39)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);

  /* "pysam/calignmentfile.pyx":1210
 *         def __get__(self):
 *             if not self._isOpen():
 *                 raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *             result = {}
 */
  __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1210; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);

  /* "pysam/calignmentfile.pyx":1218
 *                 # create 0-terminated string)
 *                 t = self.text
 *                 for line in t.split("\n"):             # <<<<<<<<<<<<<<
 *                     if not line.strip(): continue
 *                     assert line.startswith("@"), \
 */
  __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s__41); if (unlikely(!__pyx_tuple__42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);

  /* "pysam/calignmentfile.pyx":1220
 *                 for line in t.split("\n"):
 *                     if not line.strip(): continue
 *                     assert line.startswith("@"), \             # <<<<<<<<<<<<<<
 *                         "header line without '@': '%s'" % line
 *                     fields = line[1:].split("\t")
 */
  __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_s__43); if (unlikely(!__pyx_tuple__44)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);

  /* "pysam/calignmentfile.pyx":1222
 *                     assert line.startswith("@"), \
 *                         "header line without '@': '%s'" % line
 *                     fields = line[1:].split("\t")             # <<<<<<<<<<<<<<
 *                     record = fields[0]
 *                     assert record in VALID_HEADER_TYPES, \
 */
  __pyx_slice__45 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__45);
  __Pyx_GIVEREF(__pyx_slice__45);
  __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_s__46); if (unlikely(!__pyx_tuple__47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__47);
  __Pyx_GIVEREF(__pyx_tuple__47);

  /* "pysam/calignmentfile.pyx":1231
 *                         if record not in result:
 *                             result[record] = []
 *                         result[record].append("\t".join( fields[1:]))             # <<<<<<<<<<<<<<
 *                         continue
 *                     # the following is clumsy as generators do not work?
 */
  __pyx_slice__48 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__48)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__48);
  __Pyx_GIVEREF(__pyx_slice__48);

  /* "pysam/calignmentfile.pyx":1236
 *                     x = {}
 * 
 *                     for idx, field in enumerate(fields[1:]):             # <<<<<<<<<<<<<<
 *                         if ":" not in field:
 *                             raise ValueError("malformatted header: no ':' in field" )
 */
  __pyx_slice__49 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__49)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__49);
  __Pyx_GIVEREF(__pyx_slice__49);

  /* "pysam/calignmentfile.pyx":1238
 *                     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__51 = PyTuple_Pack(1, __pyx_kp_s_malformatted_header_no_in_field); if (unlikely(!__pyx_tuple__51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);

  /* "pysam/calignmentfile.pyx":1239
 *                         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_tuple__52 = PyTuple_Pack(2, __pyx_kp_s__50, __pyx_int_1); if (unlikely(!__pyx_tuple__52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__52);
  __Pyx_GIVEREF(__pyx_tuple__52);

  /* "pysam/calignmentfile.pyx":1247
 *                             # 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] = VALID_HEADER_FIELDS[record][key](value)
 *                             break
 */
  __pyx_tuple__53 = PyTuple_Pack(2, __pyx_kp_s__50, __pyx_int_1); if (unlikely(!__pyx_tuple__53)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);

  /* "pysam/calignmentfile.pyx":1356
 *         dest.text = <char*>calloc( len(text), sizeof(char))
 *         dest.l_text = len(text)
 *         cdef bytes btext = text.encode('ascii')             # <<<<<<<<<<<<<<
 *         strncpy( dest.text, btext, dest.l_text )
 * 
 */
  __pyx_tuple__54 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__54)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);

  /* "pysam/calignmentfile.pyx":1377
 *                 dest.target_name[x] = <char*>calloc(
 *                     len(seqname) + 1, sizeof(char))
 *                 bseqname = seqname.encode('ascii')             # <<<<<<<<<<<<<<
 *                 strncpy(dest.target_name[x], bseqname,
 *                         len(seqname) + 1)
 */
  __pyx_tuple__55 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);

  /* "pysam/calignmentfile.pyx":1394
 *     def __iter__(self):
 *         if not self._isOpen():
 *             raise ValueError( "I/O operation on closed file" )             # <<<<<<<<<<<<<<
 * 
 *         if not self.is_bam and self.header.n_targets == 0:
 */
  __pyx_tuple__56 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__56)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__56);
  __Pyx_GIVEREF(__pyx_tuple__56);

  /* "pysam/calignmentfile.pyx":1397
 * 
 *         if not self.is_bam and self.header.n_targets == 0:
 *             raise NotImplementedError(             # <<<<<<<<<<<<<<
 *                 "can not iterate over samfile without header")
 *         return self
 */
  __pyx_tuple__57 = PyTuple_Pack(1, __pyx_kp_s_can_not_iterate_over_samfile_wit); if (unlikely(!__pyx_tuple__57)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__57);
  __Pyx_GIVEREF(__pyx_tuple__57);

  /* "pysam/calignmentfile.pyx":1420
 *             return makeAlignedSegment(self.b)
 *         elif ret == -2:
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
  __pyx_tuple__58 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__58)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__58);
  __Pyx_GIVEREF(__pyx_tuple__58);

  /* "pysam/calignmentfile.pyx":1453
 * 
 *         if not samfile._isOpen():
 *             raise ValueError("I/O operation on closed file")             # <<<<<<<<<<<<<<
 * 
 *         # makes sure that samfile stays alive as long as the
 */
  __pyx_tuple__59 = PyTuple_Pack(1, __pyx_kp_s_I_O_operation_on_closed_file); if (unlikely(!__pyx_tuple__59)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);

  /* "pysam/calignmentfile.pyx":1507
 * 
 *         if not samfile._hasIndex():
 *             raise ValueError("no index available for iteration")             # <<<<<<<<<<<<<<
 * 
 *         self.iter = sam_itr_queryi(
 */
  __pyx_tuple__60 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_iteration); if (unlikely(!__pyx_tuple__60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1507; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__60);
  __Pyx_GIVEREF(__pyx_tuple__60);

  /* "pysam/calignmentfile.pyx":1538
 *             # returns -2 for a truncated file.
 *             # See https://github.com/pysam-developers/pysam/pull/50#issuecomment-64928625
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
  __pyx_tuple__61 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1538; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__61);
  __Pyx_GIVEREF(__pyx_tuple__61);

  /* "pysam/calignmentfile.pyx":1592
 *             return makeAlignedSegment( self.b )
 *         elif (ret == -2):
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
  __pyx_tuple__62 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__62)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__62);
  __Pyx_GIVEREF(__pyx_tuple__62);

  /* "pysam/calignmentfile.pyx":1637
 *             return makeAlignedSegment(self.b)
 *         elif (ret == -2):
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
  __pyx_tuple__63 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);

  /* "pysam/calignmentfile.pyx":1660
 * 
 *         if not samfile._hasIndex():
 *             raise ValueError("no index available for fetch")             # <<<<<<<<<<<<<<
 * 
 *         self.tid = -1
 */
  __pyx_tuple__64 = PyTuple_Pack(1, __pyx_kp_s_no_index_available_for_fetch); if (unlikely(!__pyx_tuple__64)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__64);
  __Pyx_GIVEREF(__pyx_tuple__64);

  /* "pysam/calignmentfile.pyx":1757
 *             return makeAlignedSegment(self.b)
 *         elif (ret == -2):
 *             raise IOError('truncated file')             # <<<<<<<<<<<<<<
 *         else:
 *             raise StopIteration
 */
  __pyx_tuple__65 = PyTuple_Pack(1, __pyx_kp_s_truncated_file); if (unlikely(!__pyx_tuple__65)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__65);
  __Pyx_GIVEREF(__pyx_tuple__65);

  /* "pysam/calignmentfile.pyx":2060
 *             self.cnext()
 *             if self.n_plp < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             if self.plp == NULL:
 */
  __pyx_tuple__67 = PyTuple_Pack(1, __pyx_kp_s_error_during_iteration); if (unlikely(!__pyx_tuple__67)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__67);
  __Pyx_GIVEREF(__pyx_tuple__67);

  /* "pysam/calignmentfile.pyx":2098
 * 
 *             if self.n_plp < 0:
 *                 raise ValueError("error during iteration" )             # <<<<<<<<<<<<<<
 * 
 *             # return result, if within same reference
 */
  __pyx_tuple__68 = PyTuple_Pack(1, __pyx_kp_s_error_during_iteration); if (unlikely(!__pyx_tuple__68)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__68);
  __Pyx_GIVEREF(__pyx_tuple__68);

  /* "pysam/calignmentfile.pyx":2271
 *                 valuetype = b's'
 *             elif value < -2147483648 or maximum_value >= 2147483648:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "at least one signed integer out of range of "
 *                     "BAM/SAM specification")
 */
  __pyx_tuple__71 = PyTuple_Pack(1, __pyx_kp_s_at_least_one_signed_integer_out); if (unlikely(!__pyx_tuple__71)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__71);
  __Pyx_GIVEREF(__pyx_tuple__71);

  /* "pysam/calignmentfile.pyx":2283
 *                 valuetype = b'S'
 *             elif maximum_value >= 4294967296:
 *                 raise ValueError(             # <<<<<<<<<<<<<<
 *                     "at least one integer out of range of BAM/SAM specification")
 *             else:
 */
  __pyx_tuple__72 = PyTuple_Pack(1, __pyx_kp_s_at_least_one_integer_out_of_rang); if (unlikely(!__pyx_tuple__72)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__72);
  __Pyx_GIVEREF(__pyx_tuple__72);

  /* "pysam/calignmentfile.pyx":2290
 *         # Note: hex strings (H) are not supported yet
 *         if t is not bytes:
 *             value = value.encode('ascii')             # <<<<<<<<<<<<<<
 *         if len(value) == 1:
 *             valuetype = b"A"
 */
  __pyx_tuple__73 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__73)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2290; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__73);
  __Pyx_GIVEREF(__pyx_tuple__73);

  /* "pysam/calignmentfile.pyx":2321
 * 
 *         if not type(pytag) is bytes:
 *             pytag = pytag.encode('ascii')             # <<<<<<<<<<<<<<
 * 
 *         datatype2format = {'c': 'b',
 */
  __pyx_tuple__75 = PyTuple_Pack(1, __pyx_n_s_ascii); if (unlikely(!__pyx_tuple__75)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__75);
  __Pyx_GIVEREF(__pyx_tuple__75);

  /* "pysam/calignmentfile.pyx":2345
 *             datafmt = "2sccI%i%s" % (len(value), datatype2format[valuetype])
 * 
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          b"B",
 *                          valuetype,
 */
  __pyx_slice__76 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__76)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__76);
  __Pyx_GIVEREF(__pyx_slice__76);

  /* "pysam/calignmentfile.pyx":2361
 *                 fmt = "2sc%s" % datatype2format[valuetype]
 * 
 *             args.extend([pytag[:2],             # <<<<<<<<<<<<<<
 *                          valuetype,
 *                          value])
 */
  __pyx_slice__77 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__77)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__77);
  __Pyx_GIVEREF(__pyx_slice__77);

  /* "pysam/calignmentfile.pyx":3125
 * 
 *             elif op == BAM_CPAD:
 *                 raise NotImplementedError("Padding (BAM_CPAD, 6) is currently not supported. Please implement. Sorry about that.")             # <<<<<<<<<<<<<<
 * 
 *         return result
 */
  __pyx_tuple__78 = PyTuple_Pack(1, __pyx_kp_s_Padding_BAM_CPAD_6_is_currently); if (unlikely(!__pyx_tuple__78)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__78);
  __Pyx_GIVEREF(__pyx_tuple__78);

  /* "pysam/calignmentfile.pyx":3350
 *         type_code = _get_value_code(value, value_type)
 *         if type_code == 0:
 *             raise ValueError("can't guess type or invalid type code specified")             # <<<<<<<<<<<<<<
 * 
 *         # Not Endian-safe, but then again neither is samtools!
 */
  __pyx_tuple__79 = PyTuple_Pack(1, __pyx_kp_s_can_t_guess_type_or_invalid_type); if (unlikely(!__pyx_tuple__79)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__79);
  __Pyx_GIVEREF(__pyx_tuple__79);

  /* "pysam/calignmentfile.pyx":3370
 *             value_size   = sizeof(float)
 *         else:
 *             raise ValueError('Unsupported value_type in set_option')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__80 = PyTuple_Pack(1, __pyx_kp_s_Unsupported_value_type_in_set_op); if (unlikely(!__pyx_tuple__80)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__80);
  __Pyx_GIVEREF(__pyx_tuple__80);

  /* "pysam/calignmentfile.pyx":3705
 *     '''
 *     def __init__(self):
 *         raise TypeError("this class cannot be instantiated from Python")             # <<<<<<<<<<<<<<
 * 
 *     def __str__(self):
 */
  __pyx_tuple__81 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__81)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__81);
  __Pyx_GIVEREF(__pyx_tuple__81);

  /* "pysam/calignmentfile.pyx":3739
 * 
 *             if self.plp == NULL or self.plp[0] == NULL:
 *                 raise ValueError("PileupColumn accessed after iterator finished")             # <<<<<<<<<<<<<<
 * 
 *             # warning: there could be problems if self.n and self.buf are
 */
  __pyx_tuple__82 = PyTuple_Pack(1, __pyx_kp_s_PileupColumn_accessed_after_iter); if (unlikely(!__pyx_tuple__82)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__82);
  __Pyx_GIVEREF(__pyx_tuple__82);

  /* "pysam/calignmentfile.pyx":3777
 * 
 *     def __init__(self):
 *         raise TypeError(             # <<<<<<<<<<<<<<
 *             "this class cannot be instantiated from Python")
 * 
 */
  __pyx_tuple__83 = PyTuple_Pack(1, __pyx_kp_s_this_class_cannot_be_instantiate); if (unlikely(!__pyx_tuple__83)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__83);
  __Pyx_GIVEREF(__pyx_tuple__83);

  /* "pysam/calignmentfile.pyx":115
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
 * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )             # <<<<<<<<<<<<<<
 * 
 * #####################################################################
 */
  __pyx_tuple__84 = PyTuple_Pack(1, __pyx_kp_s_d_MIDNSHP_X); if (unlikely(!__pyx_tuple__84)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__84);
  __Pyx_GIVEREF(__pyx_tuple__84);

  /* "pysam/calignmentfile.pyx":214
 * 
 * # order of records within SAM headers
 * VALID_HEADERS = ("HD", "SQ", "RG", "PG", "CO")             # <<<<<<<<<<<<<<
 * 
 * # default type conversions within SAM header records
 */
  __pyx_tuple__85 = PyTuple_Pack(5, __pyx_n_s_HD, __pyx_n_s_SQ, __pyx_n_s_RG, __pyx_n_s_PG, __pyx_n_s_CO); if (unlikely(!__pyx_tuple__85)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__85);
  __Pyx_GIVEREF(__pyx_tuple__85);

  /* "pysam/calignmentfile.pyx":228
 * 
 * # output order of fields within records
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"),             # <<<<<<<<<<<<<<
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP"),
 */
  __pyx_tuple__86 = PyTuple_Pack(3, __pyx_n_s_VN, __pyx_n_s_SO, __pyx_n_s_GO); if (unlikely(!__pyx_tuple__86)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__86);
  __Pyx_GIVEREF(__pyx_tuple__86);

  /* "pysam/calignmentfile.pyx":229
 * # output order of fields within records
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"),
 *                       "SQ" : ("SN", "LN", "AS", "M5",             # <<<<<<<<<<<<<<
 *                                "UR", "SP"),
 *                       "RG" : ("ID", "SM", "LB", "DS",
 */
  __pyx_tuple__87 = PyTuple_Pack(6, __pyx_n_s_SN, __pyx_n_s_LN, __pyx_n_s_AS, __pyx_n_s_M5, __pyx_n_s_UR, __pyx_n_s_SP); if (unlikely(!__pyx_tuple__87)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__87);
  __Pyx_GIVEREF(__pyx_tuple__87);

  /* "pysam/calignmentfile.pyx":231
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP"),
 *                       "RG" : ("ID", "SM", "LB", "DS",             # <<<<<<<<<<<<<<
 *                               "PU", "PI", "CN", "DT",
 *                               "PL", "FO", "KS", "PG"),
 */
  __pyx_tuple__88 = PyTuple_Pack(12, __pyx_n_s_ID, __pyx_n_s_SM, __pyx_n_s_LB, __pyx_n_s_DS, __pyx_n_s_PU, __pyx_n_s_PI, __pyx_n_s_CN, __pyx_n_s_DT, __pyx_n_s_PL, __pyx_n_s_FO, __pyx_n_s_KS, __pyx_n_s_PG); if (unlikely(!__pyx_tuple__88)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 231; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__88);
  __Pyx_GIVEREF(__pyx_tuple__88);

  /* "pysam/calignmentfile.pyx":234
 *                               "PU", "PI", "CN", "DT",
 *                               "PL", "FO", "KS", "PG"),
 *                       "PG" : ("PN", "ID", "VN", "CL",             # <<<<<<<<<<<<<<
 *                               "PP"),}
 * 
 */
  __pyx_tuple__89 = PyTuple_Pack(5, __pyx_n_s_PN, __pyx_n_s_ID, __pyx_n_s_VN, __pyx_n_s_CL, __pyx_n_s_PP); if (unlikely(!__pyx_tuple__89)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__89);
  __Pyx_GIVEREF(__pyx_tuple__89);

  /* "pysam/calignmentfile.pyx":2204
 * 
 * 
 * def toQualityString(qualities):             # <<<<<<<<<<<<<<
 *     '''convert a list of quality score to the string
 *     representation used in the SAM format.'''
 */
  __pyx_tuple__90 = PyTuple_Pack(2, __pyx_n_s_qualities, __pyx_n_s_x); if (unlikely(!__pyx_tuple__90)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__90);
  __Pyx_GIVEREF(__pyx_tuple__90);
  __pyx_codeobj__69 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__90, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_ifs_devel_andreas_pysam_pysam_c, __pyx_n_s_toQualityString, 2204, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__69)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":2212
 * 
 * 
 * def fromQualityString(quality_string):             # <<<<<<<<<<<<<<
 *     '''return a list of quality scores from the
 *     stringn representation of quality scores used
 */
  __pyx_tuple__91 = PyTuple_Pack(2, __pyx_n_s_quality_string, __pyx_n_s_x); if (unlikely(!__pyx_tuple__91)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__91);
  __Pyx_GIVEREF(__pyx_tuple__91);
  __pyx_codeobj__70 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__91, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_ifs_devel_andreas_pysam_pysam_c, __pyx_n_s_fromQualityString, 2212, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__70)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_15 = PyInt_FromLong(15); if (unlikely(!__pyx_int_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_33 = PyInt_FromLong(33); if (unlikely(!__pyx_int_33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_128 = PyInt_FromLong(128); if (unlikely(!__pyx_int_128)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_256 = PyInt_FromLong(256); if (unlikely(!__pyx_int_256)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_1796 = PyInt_FromLong(1796); if (unlikely(!__pyx_int_1796)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_8000 = PyInt_FromLong(8000); if (unlikely(!__pyx_int_8000)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_32768 = PyInt_FromLong(32768L); if (unlikely(!__pyx_int_32768)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_65536 = PyInt_FromLong(65536L); if (unlikely(!__pyx_int_65536)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_536870912 = PyInt_FromLong(536870912L); if (unlikely(!__pyx_int_536870912)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_2147483648 = PyInt_FromString((char *)"2147483648", 0, 0); if (unlikely(!__pyx_int_2147483648)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_4294967296 = PyInt_FromString((char *)"4294967296", 0, 0); if (unlikely(!__pyx_int_4294967296)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_neg_4 = PyInt_FromLong(-4); if (unlikely(!__pyx_int_neg_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_neg_128 = PyInt_FromLong(-128); if (unlikely(!__pyx_int_neg_128)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_neg_32768 = PyInt_FromLong(-32768L); if (unlikely(!__pyx_int_neg_32768)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_neg_2147483648 = PyInt_FromLong(-2147483648L); if (unlikely(!__pyx_int_neg_2147483648)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initcalignmentfile(void); /*proto*/
PyMODINIT_FUNC initcalignmentfile(void)
#else
PyMODINIT_FUNC PyInit_calignmentfile(void); /*proto*/
PyMODINIT_FUNC PyInit_calignmentfile(void)
#endif
{
  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_RefNannyDeclarations
  #if CYTHON_REFNANNY
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  #endif
  __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_calignmentfile(void)", 0);
  if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __Pyx_CyFunction_USED
  if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("calignmentfile", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  if (__pyx_module_is_main_pysam__calignmentfile) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!PyDict_GetItemString(modules, "pysam.calignmentfile")) {
      if (unlikely(PyDict_SetItemString(modules, "pysam.calignmentfile", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (unlikely(__Pyx_InitCachedConstants() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  __pyx_v_5pysam_14calignmentfile__FILENAME_ENCODING = ((PyObject*)Py_None); Py_INCREF(Py_None);
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  __pyx_vtabptr_5pysam_14calignmentfile_AlignedSegment = &__pyx_vtable_5pysam_14calignmentfile_AlignedSegment;
  __pyx_vtable_5pysam_14calignmentfile_AlignedSegment.set_tag = (PyObject *(*)(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_5pysam_14calignmentfile_14AlignedSegment_set_tag *__pyx_optional_args))__pyx_f_5pysam_14calignmentfile_14AlignedSegment_set_tag;
  __pyx_vtable_5pysam_14calignmentfile_AlignedSegment.get_tag = (PyObject *(*)(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *, PyObject *, int __pyx_skip_dispatch))__pyx_f_5pysam_14calignmentfile_14AlignedSegment_get_tag;
  __pyx_vtable_5pysam_14calignmentfile_AlignedSegment.has_tag = (PyObject *(*)(struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *, PyObject *, int __pyx_skip_dispatch))__pyx_f_5pysam_14calignmentfile_14AlignedSegment_has_tag;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_AlignedSegment) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_AlignedSegment.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_14calignmentfile_AlignedSegment, "__str__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_14calignmentfile_14AlignedSegment_4__str__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_14calignmentfile_14AlignedSegment_4__str__.doc = __pyx_doc_5pysam_14calignmentfile_14AlignedSegment_4__str__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_14calignmentfile_14AlignedSegment_4__str__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_14calignmentfile_AlignedSegment.tp_dict, __pyx_vtabptr_5pysam_14calignmentfile_AlignedSegment) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "AlignedSegment", (PyObject *)&__pyx_type_5pysam_14calignmentfile_AlignedSegment) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_AlignedSegment = &__pyx_type_5pysam_14calignmentfile_AlignedSegment;
  __pyx_vtabptr_5pysam_14calignmentfile_AlignmentFile = &__pyx_vtable_5pysam_14calignmentfile_AlignmentFile;
  __pyx_vtable_5pysam_14calignmentfile_AlignmentFile._buildHeader = (bam_hdr_t *(*)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, PyObject *))__pyx_f_5pysam_14calignmentfile_13AlignmentFile__buildHeader;
  __pyx_vtable_5pysam_14calignmentfile_AlignmentFile.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *))__pyx_f_5pysam_14calignmentfile_13AlignmentFile_getCurrent;
  __pyx_vtable_5pysam_14calignmentfile_AlignmentFile.cnext = (int (*)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *))__pyx_f_5pysam_14calignmentfile_13AlignmentFile_cnext;
  __pyx_vtable_5pysam_14calignmentfile_AlignmentFile.write = (int (*)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, struct __pyx_obj_5pysam_14calignmentfile_AlignedSegment *, int __pyx_skip_dispatch))__pyx_f_5pysam_14calignmentfile_13AlignmentFile_write;
  __pyx_vtable_5pysam_14calignmentfile_AlignmentFile._getrname = (char *(*)(struct __pyx_obj_5pysam_14calignmentfile_AlignmentFile *, int))__pyx_f_5pysam_14calignmentfile_13AlignmentFile__getrname;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_AlignmentFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_AlignmentFile.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_14calignmentfile_AlignmentFile, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_14calignmentfile_13AlignmentFile_48__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_14calignmentfile_13AlignmentFile_48__next__.doc = __pyx_doc_5pysam_14calignmentfile_13AlignmentFile_48__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_14calignmentfile_13AlignmentFile_48__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_14calignmentfile_AlignmentFile.tp_dict, __pyx_vtabptr_5pysam_14calignmentfile_AlignmentFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "AlignmentFile", (PyObject *)&__pyx_type_5pysam_14calignmentfile_AlignmentFile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_AlignmentFile = &__pyx_type_5pysam_14calignmentfile_AlignmentFile;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_PileupColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_PileupColumn.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "PileupColumn", (PyObject *)&__pyx_type_5pysam_14calignmentfile_PileupColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_PileupColumn = &__pyx_type_5pysam_14calignmentfile_PileupColumn;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3770; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_PileupRead.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "PileupRead", (PyObject *)&__pyx_type_5pysam_14calignmentfile_PileupRead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3770; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_PileupRead = &__pyx_type_5pysam_14calignmentfile_PileupRead;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_IteratorRow.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "IteratorRow", (PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorRow) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1425; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRow = &__pyx_type_5pysam_14calignmentfile_IteratorRow;
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowRegion = &__pyx_vtable_5pysam_14calignmentfile_IteratorRowRegion;
  __pyx_vtable_5pysam_14calignmentfile_IteratorRowRegion.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *))__pyx_f_5pysam_14calignmentfile_17IteratorRowRegion_getCurrent;
  __pyx_vtable_5pysam_14calignmentfile_IteratorRowRegion.cnext = (int (*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowRegion *))__pyx_f_5pysam_14calignmentfile_17IteratorRowRegion_cnext;
  __pyx_type_5pysam_14calignmentfile_IteratorRowRegion.tp_base = __pyx_ptype_5pysam_14calignmentfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_IteratorRowRegion.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorRowRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_14calignmentfile_17IteratorRowRegion_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_14calignmentfile_17IteratorRowRegion_4__next__.doc = __pyx_doc_5pysam_14calignmentfile_17IteratorRowRegion_4__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_14calignmentfile_17IteratorRowRegion_4__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_14calignmentfile_IteratorRowRegion.tp_dict, __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "IteratorRowRegion", (PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorRowRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowRegion = &__pyx_type_5pysam_14calignmentfile_IteratorRowRegion;
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowHead = &__pyx_vtable_5pysam_14calignmentfile_IteratorRowHead;
  __pyx_vtable_5pysam_14calignmentfile_IteratorRowHead.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *))__pyx_f_5pysam_14calignmentfile_15IteratorRowHead_getCurrent;
  __pyx_vtable_5pysam_14calignmentfile_IteratorRowHead.cnext = (int (*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowHead *))__pyx_f_5pysam_14calignmentfile_15IteratorRowHead_cnext;
  __pyx_type_5pysam_14calignmentfile_IteratorRowHead.tp_base = __pyx_ptype_5pysam_14calignmentfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_IteratorRowHead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_IteratorRowHead.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorRowHead, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_14calignmentfile_15IteratorRowHead_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_14calignmentfile_15IteratorRowHead_4__next__.doc = __pyx_doc_5pysam_14calignmentfile_15IteratorRowHead_4__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_14calignmentfile_15IteratorRowHead_4__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_14calignmentfile_IteratorRowHead.tp_dict, __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowHead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "IteratorRowHead", (PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorRowHead) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowHead = &__pyx_type_5pysam_14calignmentfile_IteratorRowHead;
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowAll = &__pyx_vtable_5pysam_14calignmentfile_IteratorRowAll;
  __pyx_vtable_5pysam_14calignmentfile_IteratorRowAll.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *))__pyx_f_5pysam_14calignmentfile_14IteratorRowAll_getCurrent;
  __pyx_vtable_5pysam_14calignmentfile_IteratorRowAll.cnext = (int (*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowAll *))__pyx_f_5pysam_14calignmentfile_14IteratorRowAll_cnext;
  __pyx_type_5pysam_14calignmentfile_IteratorRowAll.tp_base = __pyx_ptype_5pysam_14calignmentfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_IteratorRowAll.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorRowAll, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_14calignmentfile_14IteratorRowAll_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_14calignmentfile_14IteratorRowAll_4__next__.doc = __pyx_doc_5pysam_14calignmentfile_14IteratorRowAll_4__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_14calignmentfile_14IteratorRowAll_4__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_14calignmentfile_IteratorRowAll.tp_dict, __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "IteratorRowAll", (PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorRowAll) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowAll = &__pyx_type_5pysam_14calignmentfile_IteratorRowAll;
  __pyx_type_5pysam_14calignmentfile_IteratorRowAllRefs.tp_base = __pyx_ptype_5pysam_14calignmentfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_IteratorRowAllRefs.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorRowAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_14calignmentfile_18IteratorRowAllRefs_6__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_14calignmentfile_18IteratorRowAllRefs_6__next__.doc = __pyx_doc_5pysam_14calignmentfile_18IteratorRowAllRefs_6__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_14calignmentfile_18IteratorRowAllRefs_6__next__;
    }
  }
  #endif
  if (PyObject_SetAttrString(__pyx_m, "IteratorRowAllRefs", (PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorRowAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowAllRefs = &__pyx_type_5pysam_14calignmentfile_IteratorRowAllRefs;
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowSelection = &__pyx_vtable_5pysam_14calignmentfile_IteratorRowSelection;
  __pyx_vtable_5pysam_14calignmentfile_IteratorRowSelection.getCurrent = (bam1_t *(*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *))__pyx_f_5pysam_14calignmentfile_20IteratorRowSelection_getCurrent;
  __pyx_vtable_5pysam_14calignmentfile_IteratorRowSelection.cnext = (int (*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorRowSelection *))__pyx_f_5pysam_14calignmentfile_20IteratorRowSelection_cnext;
  __pyx_type_5pysam_14calignmentfile_IteratorRowSelection.tp_base = __pyx_ptype_5pysam_14calignmentfile_IteratorRow;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_IteratorRowSelection.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorRowSelection, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_14calignmentfile_20IteratorRowSelection_4__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_14calignmentfile_20IteratorRowSelection_4__next__.doc = __pyx_doc_5pysam_14calignmentfile_20IteratorRowSelection_4__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_14calignmentfile_20IteratorRowSelection_4__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_14calignmentfile_IteratorRowSelection.tp_dict, __pyx_vtabptr_5pysam_14calignmentfile_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "IteratorRowSelection", (PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorRowSelection) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1711; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorRowSelection = &__pyx_type_5pysam_14calignmentfile_IteratorRowSelection;
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumn = &__pyx_vtable_5pysam_14calignmentfile_IteratorColumn;
  __pyx_vtable_5pysam_14calignmentfile_IteratorColumn.cnext = (int (*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *))__pyx_f_5pysam_14calignmentfile_14IteratorColumn_cnext;
  __pyx_vtable_5pysam_14calignmentfile_IteratorColumn.getSequence = (char *(*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *))__pyx_f_5pysam_14calignmentfile_14IteratorColumn_getSequence;
  __pyx_vtable_5pysam_14calignmentfile_IteratorColumn.setMask = (PyObject *(*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *, PyObject *))__pyx_f_5pysam_14calignmentfile_14IteratorColumn_setMask;
  __pyx_vtable_5pysam_14calignmentfile_IteratorColumn.setupIteratorData = (PyObject *(*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData *__pyx_optional_args))__pyx_f_5pysam_14calignmentfile_14IteratorColumn_setupIteratorData;
  __pyx_vtable_5pysam_14calignmentfile_IteratorColumn.reset = (PyObject *(*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *, PyObject *, PyObject *, PyObject *))__pyx_f_5pysam_14calignmentfile_14IteratorColumn_reset;
  __pyx_vtable_5pysam_14calignmentfile_IteratorColumn._free_pileup_iter = (PyObject *(*)(struct __pyx_obj_5pysam_14calignmentfile_IteratorColumn *))__pyx_f_5pysam_14calignmentfile_14IteratorColumn__free_pileup_iter;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_IteratorColumn.tp_print = 0;
  if (__Pyx_SetVtable(__pyx_type_5pysam_14calignmentfile_IteratorColumn.tp_dict, __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "IteratorColumn", (PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorColumn) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorColumn = &__pyx_type_5pysam_14calignmentfile_IteratorColumn;
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnRegion = &__pyx_vtable_5pysam_14calignmentfile_IteratorColumnRegion;
  __pyx_vtable_5pysam_14calignmentfile_IteratorColumnRegion.__pyx_base = *__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumn;
  __pyx_type_5pysam_14calignmentfile_IteratorColumnRegion.tp_base = __pyx_ptype_5pysam_14calignmentfile_IteratorColumn;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_IteratorColumnRegion.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorColumnRegion, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_14calignmentfile_20IteratorColumnRegion_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_14calignmentfile_20IteratorColumnRegion_2__next__.doc = __pyx_doc_5pysam_14calignmentfile_20IteratorColumnRegion_2__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_14calignmentfile_20IteratorColumnRegion_2__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_14calignmentfile_IteratorColumnRegion.tp_dict, __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "IteratorColumnRegion", (PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorColumnRegion) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorColumnRegion = &__pyx_type_5pysam_14calignmentfile_IteratorColumnRegion;
  __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnAllRefs = &__pyx_vtable_5pysam_14calignmentfile_IteratorColumnAllRefs;
  __pyx_vtable_5pysam_14calignmentfile_IteratorColumnAllRefs.__pyx_base = *__pyx_vtabptr_5pysam_14calignmentfile_IteratorColumn;
  __pyx_type_5pysam_14calignmentfile_IteratorColumnAllRefs.tp_base = __pyx_ptype_5pysam_14calignmentfile_IteratorColumn;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_IteratorColumnAllRefs.tp_print = 0;
  #if CYTHON_COMPILING_IN_CPYTHON
  {
    PyObject *wrapper = PyObject_GetAttrString((PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorColumnAllRefs, "__next__"); if (unlikely(!wrapper)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {
      __pyx_wrapperbase_5pysam_14calignmentfile_21IteratorColumnAllRefs_2__next__ = *((PyWrapperDescrObject *)wrapper)->d_base;
      __pyx_wrapperbase_5pysam_14calignmentfile_21IteratorColumnAllRefs_2__next__.doc = __pyx_doc_5pysam_14calignmentfile_21IteratorColumnAllRefs_2__next__;
      ((PyWrapperDescrObject *)wrapper)->d_base = &__pyx_wrapperbase_5pysam_14calignmentfile_21IteratorColumnAllRefs_2__next__;
    }
  }
  #endif
  if (__Pyx_SetVtable(__pyx_type_5pysam_14calignmentfile_IteratorColumnAllRefs.tp_dict, __pyx_vtabptr_5pysam_14calignmentfile_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyObject_SetAttrString(__pyx_m, "IteratorColumnAllRefs", (PyObject *)&__pyx_type_5pysam_14calignmentfile_IteratorColumnAllRefs) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IteratorColumnAllRefs = &__pyx_type_5pysam_14calignmentfile_IteratorColumnAllRefs;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_IndexedReads.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "IndexedReads", (PyObject *)&__pyx_type_5pysam_14calignmentfile_IndexedReads) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3891; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_IndexedReads = &__pyx_type_5pysam_14calignmentfile_IndexedReads;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile_SNPCall.tp_print = 0;
  if (PyObject_SetAttrString(__pyx_m, "SNPCall", (PyObject *)&__pyx_type_5pysam_14calignmentfile_SNPCall) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_14calignmentfile_SNPCall = &__pyx_type_5pysam_14calignmentfile_SNPCall;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile___pyx_scope_struct__genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile___pyx_scope_struct__genexpr.tp_print = 0;
  __pyx_ptype_5pysam_14calignmentfile___pyx_scope_struct__genexpr = &__pyx_type_5pysam_14calignmentfile___pyx_scope_struct__genexpr;
  if (PyType_Ready(&__pyx_type_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_type_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr.tp_print = 0;
  __pyx_ptype_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr = &__pyx_type_5pysam_14calignmentfile___pyx_scope_struct_1_genexpr;
  /*--- Type import code ---*/
  __pyx_ptype_5pysam_6cfaidx_FastaFile = __Pyx_ImportType("pysam.cfaidx", "FastaFile", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastaFile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastaFile)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_FastaFile = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastaFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_FastaFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_FastaFile)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastqProxy = __Pyx_ImportType("pysam.cfaidx", "FastqProxy", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastqProxy), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastqProxy)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastxFile = __Pyx_ImportType("pysam.cfaidx", "FastxFile", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastxFile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastxFile)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_FastxFile = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastxFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_FastxFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_FastxFile)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_FastqFile = __Pyx_ImportType("pysam.cfaidx", "FastqFile", sizeof(struct __pyx_obj_5pysam_6cfaidx_FastqFile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_FastqFile)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_FastqFile = (struct __pyx_vtabstruct_5pysam_6cfaidx_FastqFile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_FastqFile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_FastqFile)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_Fastafile = __Pyx_ImportType("pysam.cfaidx", "Fastafile", sizeof(struct __pyx_obj_5pysam_6cfaidx_Fastafile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_Fastafile)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_Fastafile = (struct __pyx_vtabstruct_5pysam_6cfaidx_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_Fastafile)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_6cfaidx_Fastqfile = __Pyx_ImportType("pysam.cfaidx", "Fastqfile", sizeof(struct __pyx_obj_5pysam_6cfaidx_Fastqfile), 1); if (unlikely(!__pyx_ptype_5pysam_6cfaidx_Fastqfile)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_6cfaidx_Fastqfile = (struct __pyx_vtabstruct_5pysam_6cfaidx_Fastqfile*)__Pyx_GetVtable(__pyx_ptype_5pysam_6cfaidx_Fastqfile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_6cfaidx_Fastqfile)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if CYTHON_COMPILING_IN_PYPY
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) {__pyx_filename = __pyx_f[6]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_5array_array = __Pyx_ImportType("array", "array", sizeof(arrayobject), 0); if (unlikely(!__pyx_ptype_7cpython_5array_array)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "pysam/calignmentfile.pyx":4
 * # cython: profile=True
 * # adds doc-strings for sphinx
 * import tempfile             # <<<<<<<<<<<<<<
 * import os
 * import sys
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_tempfile, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_tempfile, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":5
 * # adds doc-strings for sphinx
 * import tempfile
 * import os             # <<<<<<<<<<<<<<
 * import sys
 * import types
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":6
 * import tempfile
 * import os
 * import sys             # <<<<<<<<<<<<<<
 * import types
 * import itertools
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":7
 * import os
 * import sys
 * import types             # <<<<<<<<<<<<<<
 * import itertools
 * import struct
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_types, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_types, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":8
 * import sys
 * import types
 * import itertools             # <<<<<<<<<<<<<<
 * import struct
 * import ctypes
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_itertools, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_itertools, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":9
 * import types
 * import itertools
 * import struct             # <<<<<<<<<<<<<<
 * import ctypes
 * import collections
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_struct, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_struct, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":10
 * import itertools
 * import struct
 * import ctypes             # <<<<<<<<<<<<<<
 * import collections
 * import re
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_ctypes, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ctypes, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":11
 * import struct
 * import ctypes
 * import collections             # <<<<<<<<<<<<<<
 * import re
 * import platform
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_collections, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_collections, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":12
 * import ctypes
 * import collections
 * import re             # <<<<<<<<<<<<<<
 * import platform
 * import warnings
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_re, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":13
 * import collections
 * import re
 * import platform             # <<<<<<<<<<<<<<
 * import warnings
 * import array
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_platform, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_platform, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":14
 * import re
 * import platform
 * import warnings             # <<<<<<<<<<<<<<
 * import array
 * 
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_warnings, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_warnings, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":15
 * import platform
 * import warnings
 * import array             # <<<<<<<<<<<<<<
 * 
 * from cpython cimport PyErr_SetString, \
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_array, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_array, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":33
 * ## Python 3 compatibility functions
 * ########################################################################
 * IS_PYTHON3 = PY_MAJOR_VERSION >= 3             # <<<<<<<<<<<<<<
 * cdef from_string_and_size(char* s, size_t length):
 *     if PY_MAJOR_VERSION < 3:
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong((PY_MAJOR_VERSION >= 3)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_IS_PYTHON3, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":42
 * # filename encoding (copied from lxml.etree.pyx)
 * cdef str _FILENAME_ENCODING
 * _FILENAME_ENCODING = sys.getfilesystemencoding()             # <<<<<<<<<<<<<<
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_getfilesystemencoding); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_XGOTREF(__pyx_v_5pysam_14calignmentfile__FILENAME_ENCODING);
  __Pyx_DECREF_SET(__pyx_v_5pysam_14calignmentfile__FILENAME_ENCODING, ((PyObject*)__pyx_t_1));
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":43
 * cdef str _FILENAME_ENCODING
 * _FILENAME_ENCODING = sys.getfilesystemencoding()
 * if _FILENAME_ENCODING is None:             # <<<<<<<<<<<<<<
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 * if _FILENAME_ENCODING is None:
 */
  __pyx_t_4 = (__pyx_v_5pysam_14calignmentfile__FILENAME_ENCODING == ((PyObject*)Py_None));
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "pysam/calignmentfile.pyx":44
 * _FILENAME_ENCODING = sys.getfilesystemencoding()
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = sys.getdefaultencoding()             # <<<<<<<<<<<<<<
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = 'ascii'
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_getdefaultencoding); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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);
      }
    }
    if (__pyx_t_3) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(PyString_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "str", Py_TYPE(__pyx_t_1)->tp_name), 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XGOTREF(__pyx_v_5pysam_14calignmentfile__FILENAME_ENCODING);
    __Pyx_DECREF_SET(__pyx_v_5pysam_14calignmentfile__FILENAME_ENCODING, ((PyObject*)__pyx_t_1));
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "pysam/calignmentfile.pyx":45
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 * if _FILENAME_ENCODING is None:             # <<<<<<<<<<<<<<
 *     _FILENAME_ENCODING = 'ascii'
 * 
 */
  __pyx_t_5 = (__pyx_v_5pysam_14calignmentfile__FILENAME_ENCODING == ((PyObject*)Py_None));
  __pyx_t_4 = (__pyx_t_5 != 0);
  if (__pyx_t_4) {

    /* "pysam/calignmentfile.pyx":46
 *     _FILENAME_ENCODING = sys.getdefaultencoding()
 * if _FILENAME_ENCODING is None:
 *     _FILENAME_ENCODING = 'ascii'             # <<<<<<<<<<<<<<
 * 
 * #cdef char* _C_FILENAME_ENCODING
 */
    __Pyx_INCREF(__pyx_n_s_ascii);
    __Pyx_XGOTREF(__pyx_v_5pysam_14calignmentfile__FILENAME_ENCODING);
    __Pyx_DECREF_SET(__pyx_v_5pysam_14calignmentfile__FILENAME_ENCODING, __pyx_n_s_ascii);
    __Pyx_GIVEREF(__pyx_n_s_ascii);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysam/calignmentfile.pyx":110
 * DEF SEEK_END = 2
 * 
 * cdef char* CODE2CIGAR= "MIDNSHP=X"             # <<<<<<<<<<<<<<
 * if IS_PYTHON3:
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
 */
  __pyx_v_5pysam_14calignmentfile_CODE2CIGAR = __pyx_k_MIDNSHP_X;

  /* "pysam/calignmentfile.pyx":111
 * 
 * cdef char* CODE2CIGAR= "MIDNSHP=X"
 * if IS_PYTHON3:             # <<<<<<<<<<<<<<
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
 * else:
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_IS_PYTHON3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {

    /* "pysam/calignmentfile.pyx":112
 * cdef char* CODE2CIGAR= "MIDNSHP=X"
 * if IS_PYTHON3:
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
 */
    __pyx_t_1 = __pyx_pf_5pysam_14calignmentfile_8genexpr(NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR2CODE, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "pysam/calignmentfile.pyx":114
 *     CIGAR2CODE = dict( [y,x] for x,y in enumerate( CODE2CIGAR) )
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )             # <<<<<<<<<<<<<<
 * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )
 * 
 */
    __pyx_t_1 = __pyx_pf_5pysam_14calignmentfile_11genexpr(NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)((PyObject*)(&PyDict_Type))), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR2CODE, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L4:;

  /* "pysam/calignmentfile.pyx":115
 * else:
 *     CIGAR2CODE = dict( [ord(y),x] for x,y in enumerate( CODE2CIGAR) )
 * CIGAR_REGEX = re.compile( "(\d+)([MIDNSHP=X])" )             # <<<<<<<<<<<<<<
 * 
 * #####################################################################
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_compile); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__84, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_CIGAR_REGEX, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":119
 * #####################################################################
 * # hard-coded constants
 * cdef int max_pos = 2 << 29             # <<<<<<<<<<<<<<
 * 
 * #####################################################################
 */
  __pyx_v_5pysam_14calignmentfile_max_pos = 1073741824;

  /* "pysam/calignmentfile.pyx":207
 * 
 * # valid types for SAM headers
 * VALID_HEADER_TYPES = {"HD" : dict,             # <<<<<<<<<<<<<<
 *                       "SQ" : list,
 *                       "RG" : list,
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, ((PyObject *)((PyObject*)(&PyDict_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":208
 * # valid types for SAM headers
 * VALID_HEADER_TYPES = {"HD" : dict,
 *                       "SQ" : list,             # <<<<<<<<<<<<<<
 *                       "RG" : list,
 *                       "PG" : list,
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ, ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":209
 * VALID_HEADER_TYPES = {"HD" : dict,
 *                       "SQ" : list,
 *                       "RG" : list,             # <<<<<<<<<<<<<<
 *                       "PG" : list,
 *                       "CO" : list}
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":210
 *                       "SQ" : list,
 *                       "RG" : list,
 *                       "PG" : list,             # <<<<<<<<<<<<<<
 *                       "CO" : list}
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":211
 *                       "RG" : list,
 *                       "PG" : list,
 *                       "CO" : list}             # <<<<<<<<<<<<<<
 * 
 * # order of records within SAM headers
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_CO, ((PyObject *)((PyObject*)(&PyList_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_TYPES, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 207; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":214
 * 
 * # 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__85) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":217
 * 
 * # default type conversions within SAM header records
 * VALID_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str},             # <<<<<<<<<<<<<<
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 *                                "M5" : str, "SP" : str, "UR" : str,},
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_VN, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_SO, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_GO, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":218
 * # default type conversions within SAM header records
 * VALID_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str},
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,             # <<<<<<<<<<<<<<
 *                                "M5" : str, "SP" : str, "UR" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_SN, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_LN, ((PyObject *)((PyObject*)(&PyInt_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_AS, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":219
 * VALID_HEADER_FIELDS = {"HD" : {"VN" : str, "SO" : str, "GO" : str},
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 *                                "M5" : str, "SP" : str, "UR" : str,},             # <<<<<<<<<<<<<<
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_M5, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_SP, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_UR, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":220
 *                        "SQ" : {"SN" : str, "LN" : int, "AS" : str,
 *                                "M5" : str, "SP" : str, "UR" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,             # <<<<<<<<<<<<<<
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_ID, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_CN, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_DS, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":221
 *                                "M5" : str, "SP" : str, "UR" : str,},
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,             # <<<<<<<<<<<<<<
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PU" : str, "SM" : str,},
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_DT, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_FO, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_KS, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":222
 *                        "RG" : {"ID" : str, "CN" : str, "DS" : str,
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,             # <<<<<<<<<<<<<<
 *                                "PL" : str, "PU" : str, "SM" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_LB, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PG, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PI, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":223
 *                                "DT" : str, "FO" : str, "KS" : str,
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PU" : str, "SM" : str,},             # <<<<<<<<<<<<<<
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 *                                "PP" : str, "DS" : str, "VN" : str,},}
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PL, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PU, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_SM, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 220; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysam/calignmentfile.pyx":224
 *                                "LB" : str, "PG" : str, "PI" : str,
 *                                "PL" : str, "PU" : str, "SM" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,             # <<<<<<<<<<<<<<
 *                                "PP" : str, "DS" : str, "VN" : str,},}
 * 
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_ID, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PN, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_CL, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":225
 *                                "PL" : str, "PU" : str, "SM" : str,},
 *                        "PG" : {"ID" : str, "PN" : str, "CL" : str,
 *                                "PP" : str, "DS" : str, "VN" : str,},}             # <<<<<<<<<<<<<<
 * 
 * # output order of fields within records
 */
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_PP, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_DS, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_VN, ((PyObject *)((PyObject*)(&PyString_Type)))) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 224; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_FIELDS, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":228
 * 
 * # output order of fields within records
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"),             # <<<<<<<<<<<<<<
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP"),
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_HD, __pyx_tuple__86) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":229
 * # output order of fields within records
 * VALID_HEADER_ORDER = {"HD" : ("VN", "SO", "GO"),
 *                       "SQ" : ("SN", "LN", "AS", "M5",             # <<<<<<<<<<<<<<
 *                                "UR", "SP"),
 *                       "RG" : ("ID", "SM", "LB", "DS",
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_SQ, __pyx_tuple__87) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":231
 *                       "SQ" : ("SN", "LN", "AS", "M5",
 *                                "UR", "SP"),
 *                       "RG" : ("ID", "SM", "LB", "DS",             # <<<<<<<<<<<<<<
 *                               "PU", "PI", "CN", "DT",
 *                               "PL", "FO", "KS", "PG"),
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_RG, __pyx_tuple__88) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysam/calignmentfile.pyx":234
 *                               "PU", "PI", "CN", "DT",
 *                               "PL", "FO", "KS", "PG"),
 *                       "PG" : ("PN", "ID", "VN", "CL",             # <<<<<<<<<<<<<<
 *                               "PP"),}
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_PG, __pyx_tuple__89) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_VALID_HEADER_ORDER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 228; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":2043
 *                   int tid = 0,
 *                   int start = 0,
 *                   int end = max_pos,             # <<<<<<<<<<<<<<
 *                   int truncate = False,
 *                   **kwargs ):
 */
  __pyx_k__66 = __pyx_v_5pysam_14calignmentfile_max_pos;

  /* "pysam/calignmentfile.pyx":2204
 * 
 * 
 * def toQualityString(qualities):             # <<<<<<<<<<<<<<
 *     '''convert a list of quality score to the string
 *     representation used in the SAM format.'''
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_14calignmentfile_1toQualityString, NULL, __pyx_n_s_pysam_calignmentfile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_toQualityString, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2204; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":2212
 * 
 * 
 * def fromQualityString(quality_string):             # <<<<<<<<<<<<<<
 *     '''return a list of quality scores from the
 *     stringn representation of quality scores used
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5pysam_14calignmentfile_3fromQualityString, NULL, __pyx_n_s_pysam_calignmentfile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fromQualityString, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2212; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":3975
 *     return hts_get_verbosity()
 * 
 * __all__ = ["AlignmentFile",             # <<<<<<<<<<<<<<
 *            "IteratorRow",
 *            "IteratorColumn",
 */
  __pyx_t_1 = PyList_New(11); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_AlignmentFile);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_AlignmentFile);
  __Pyx_GIVEREF(__pyx_n_s_AlignmentFile);
  __Pyx_INCREF(__pyx_n_s_IteratorRow);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_IteratorRow);
  __Pyx_GIVEREF(__pyx_n_s_IteratorRow);
  __Pyx_INCREF(__pyx_n_s_IteratorColumn);
  PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_s_IteratorColumn);
  __Pyx_GIVEREF(__pyx_n_s_IteratorColumn);
  __Pyx_INCREF(__pyx_n_s_AlignedSegment);
  PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_s_AlignedSegment);
  __Pyx_GIVEREF(__pyx_n_s_AlignedSegment);
  __Pyx_INCREF(__pyx_n_s_PileupColumn);
  PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_s_PileupColumn);
  __Pyx_GIVEREF(__pyx_n_s_PileupColumn);
  __Pyx_INCREF(__pyx_n_s_PileupRead);
  PyList_SET_ITEM(__pyx_t_1, 5, __pyx_n_s_PileupRead);
  __Pyx_GIVEREF(__pyx_n_s_PileupRead);
  __Pyx_INCREF(__pyx_n_s_IndexedReads);
  PyList_SET_ITEM(__pyx_t_1, 6, __pyx_n_s_IndexedReads);
  __Pyx_GIVEREF(__pyx_n_s_IndexedReads);
  __Pyx_INCREF(__pyx_n_s_toQualityString);
  PyList_SET_ITEM(__pyx_t_1, 7, __pyx_n_s_toQualityString);
  __Pyx_GIVEREF(__pyx_n_s_toQualityString);
  __Pyx_INCREF(__pyx_n_s_fromQualityString);
  PyList_SET_ITEM(__pyx_t_1, 8, __pyx_n_s_fromQualityString);
  __Pyx_GIVEREF(__pyx_n_s_fromQualityString);
  __Pyx_INCREF(__pyx_n_s_get_verbosity);
  PyList_SET_ITEM(__pyx_t_1, 9, __pyx_n_s_get_verbosity);
  __Pyx_GIVEREF(__pyx_n_s_get_verbosity);
  __Pyx_INCREF(__pyx_n_s_set_verbosity);
  PyList_SET_ITEM(__pyx_t_1, 10, __pyx_n_s_set_verbosity);
  __Pyx_GIVEREF(__pyx_n_s_set_verbosity);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_all_2, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysam/calignmentfile.pyx":1
 * # cython: embedsignature=True             # <<<<<<<<<<<<<<
 * # cython: profile=True
 * # adds doc-strings for sphinx
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "array.pxd":159
 *     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)
 */

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init pysam.calignmentfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init pysam.calignmentfile");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* --- Runtime support code --- */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

#if CYTHON_PROFILE
static int __Pyx_TraceSetupAndCall(PyCodeObject** code,
                                   PyFrameObject** frame,
                                   const char *funcname,
                                   const char *srcfile,
                                   int firstlineno) {
    int retval;
    PyThreadState* tstate = PyThreadState_GET();
    if (*frame == NULL || !CYTHON_PROFILE_REUSE_FRAME) {
        if (*code == NULL) {
            *code = __Pyx_createFrameCodeObject(funcname, srcfile, firstlineno);
            if (*code == NULL) return 0;
        }
        *frame = PyFrame_New(
            tstate,                          /*PyThreadState *tstate*/
            *code,                           /*PyCodeObject *code*/
            __pyx_d,                  /*PyObject *globals*/
            0                                /*PyObject *locals*/
        );
        if (*frame == NULL) return 0;
        if (CYTHON_TRACE && (*frame)->f_trace == NULL) {
            Py_INCREF(Py_None);
            (*frame)->f_trace = Py_None;
        }
#if PY_VERSION_HEX < 0x030400B1
    } else {
        (*frame)->f_tstate = tstate;
#endif
    }
    (*frame)->f_lineno = firstlineno;
    retval = 1;
    tstate->tracing++;
    tstate->use_tracing = 0;
    #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;
    tstate->use_tracing = (tstate->c_profilefunc ||
                           (CYTHON_TRACE && tstate->c_tracefunc));
    tstate->tracing--;
    return tstate->use_tracing && retval;
}
static PyCodeObject *__Pyx_createFrameCodeObject(const char *funcname, const char *srcfile, int firstlineno) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyCodeObject *py_code = 0;
    #if PY_MAJOR_VERSION < 3
    py_funcname = PyString_FromString(funcname);
    py_srcfile = PyString_FromString(srcfile);
    #else
    py_funcname = PyUnicode_FromString(funcname);
    py_srcfile = PyUnicode_FromString(srcfile);
    #endif
    if (!py_funcname | !py_srcfile) goto bad;
    py_code = PyCode_New(
        0,
        #if PY_MAJOR_VERSION >= 3
        0,
        #endif
        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,*/
        firstlineno,
        __pyx_empty_bytes      /*PyObject *lnotab*/
    );
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return py_code;
}
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (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

static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
         const char* cstring, Py_ssize_t start, Py_ssize_t stop,
         const char* encoding, const char* errors,
         PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
    Py_ssize_t length;
    if (unlikely((start < 0) | (stop < 0))) {
        length = strlen(cstring);
        if (start < 0) {
            start += length;
            if (start < 0)
                start = 0;
        }
        if (stop < 0)
            stop += length;
    }
    length = stop - start;
    if (unlikely(length <= 0))
        return PyUnicode_FromUnicode(NULL, 0);
    cstring += start;
    if (decode_func) {
        return decode_func(cstring, length, errors);
    } else {
        return PyUnicode_Decode(cstring, length, encoding, errors);
    }
}

#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

#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) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject* args = PyTuple_Pack(1, arg);
    return (likely(args)) ? __Pyx_PyObject_Call(func, args, NULL) : NULL;
}
#endif

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_Restore(type, value, tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(type, value, tb);
#endif
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (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_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) {
                if (PyObject_IsSubclass(instance_class, type)) {
                    type = instance_class;
                } else {
                    instance_class = NULL;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
#if PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#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 = PyThreadState_GET();
        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

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

static CYTHON_INLINE 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_CheckExact(key)) && unlikely(!PyString_Check(key)))
        #endif
            if (unlikely(!PyUnicode_Check(key)))
                goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    return 0;
#endif
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) {
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
}
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (likely(Py_TYPE(obj) == type)) return 1;
        #if PY_MAJOR_VERSION == 2
        else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(PyObject_TypeCheck(obj, type))) return 1;
    }
    __Pyx_RaiseArgumentTypeInvalid(name, obj, type);
    return 0;
}

static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
#else
    PyErr_GetExcInfo(type, value, tb);
#endif
}
static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(type, value, tb);
#endif
}

static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_COMPILING_IN_CPYTHON
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (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;
        }
        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_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
}

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#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

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (PyErr_ExceptionMatches(PyExc_OverflowError))
                        PyErr_Clear();
                    else
                        return NULL;
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
    PyObject *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto bad;
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *args;
            PyObject *function = PyMethod_GET_FUNCTION(method);
            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);
            Py_INCREF(function);
            Py_DECREF(method); method = NULL;
            result = __Pyx_PyObject_Call(function, args, NULL);
            Py_DECREF(args);
            Py_DECREF(function);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallOneArg(method, arg);
bad:
    Py_XDECREF(method);
    return result;
}

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;
}

#if !CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) {
    return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL);
}
#endif

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON
    result = PyDict_GetItem(__pyx_d, name);
    if (likely(result)) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (PyErr_ExceptionMatches(PyExc_OverflowError))
                    PyErr_Clear();
                else
                    goto bad;
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_COMPILING_IN_CPYTHON
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
}

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(exc_type == PyExc_StopIteration) || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
    PyObject* value;
#if PY_MAJOR_VERSION >= 3
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (unlikely(PyErr_Occurred()))
            return NULL;
        value = default_value;
    }
    Py_INCREF(value);
#else
    if (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key)) {
        value = PyDict_GetItem(d, key);
        if (unlikely(!value)) {
            value = default_value;
        }
        Py_INCREF(value);
    } else {
        if (default_value == Py_None)
            default_value = NULL;
        value = PyObject_CallMethodObjArgs(
            d, __pyx_n_s_get, key, default_value, NULL);
    }
#endif
    return value;
}

static CYTHON_INLINE long __Pyx_div_long(long a, long b) {
    long q = a / b;
    long r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

static CYTHON_INLINE long __Pyx_mod_long(long a, long b) {
    long r = a % b;
    r += ((r != 0) & ((r ^ b) < 0)) * b;
    return r;
}

static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
#if PY_VERSION_HEX >= 0x02070000
    PyObject *ob = PyCapsule_New(vtable, 0, 0);
#else
    PyObject *ob = PyCObject_FromVoidPtr(vtable, 0);
#endif
    if (!ob)
        goto bad;
    if (PyDict_SetItem(dict, __pyx_n_s_pyx_vtable, ob) < 0)
        goto bad;
    Py_DECREF(ob);
    return 0;
bad:
    Py_XDECREF(ob);
    return -1;
}

static void* __Pyx_GetVtable(PyObject *dict) {
    void* ptr;
    PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable);
    if (!ob)
        goto bad;
#if PY_VERSION_HEX >= 0x02070000
    ptr = PyCapsule_GetPointer(ob, 0);
#else
    ptr = PyCObject_AsVoidPtr(ob);
#endif
    if (!ptr && !PyErr_Occurred())
        PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
    Py_DECREF(ob);
    return ptr;
bad:
    Py_XDECREF(ob);
    return NULL;
}

static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = (start + end) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, (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);
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        0,
        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);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        __pyx_d,      /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = py_line;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_VERSION_HEX < 0x03030000
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                #if PY_VERSION_HEX < 0x03030000
                PyObject *py_level = PyInt_FromLong(1);
                if (!py_level)
                    goto bad;
                module = PyObject_CallFunctionObjArgs(py_import,
                    name, global_dict, empty_dict, list, py_level, NULL);
                Py_DECREF(py_level);
                #else
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                #endif
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_VERSION_HEX < 0x03030000
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)       \
    {                                                                     \
        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 (is_unsigned && unlikely(value < zero))                \
                    goto raise_neg_overflow;                              \
                else                                                      \
                    goto raise_overflow;                                  \
            }                                                             \
        }                                                                 \
        return (target_type) value;                                       \
    }

#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
 #endif
#endif

static CYTHON_INLINE uint64_t __Pyx_PyInt_As_uint64_t(PyObject *x) {
    const uint64_t neg_one = (uint64_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(uint64_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(uint64_t, long, PyInt_AS_LONG(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_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint64_t, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(uint64_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(uint64_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(uint64_t, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint64_t,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(uint64_t, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(uint64_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(uint64_t, long, PyLong_AsLong(x))
            } else if (sizeof(uint64_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(uint64_t, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            uint64_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (uint64_t) -1;
        }
    } else {
        uint64_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (uint64_t) -1;
        val = __Pyx_PyInt_As_uint64_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
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;
}

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(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_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(int, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(int) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(int, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(int, long, PyLong_AsLong(x))
            } else if (sizeof(int) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(int, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
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;
}

static CYTHON_INLINE uint32_t __Pyx_PyInt_As_uint32_t(PyObject *x) {
    const uint32_t neg_one = (uint32_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(uint32_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(uint32_t, long, PyInt_AS_LONG(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_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint32_t, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(uint32_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(uint32_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(uint32_t, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint32_t,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(uint32_t, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(uint32_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(uint32_t, long, PyLong_AsLong(x))
            } else if (sizeof(uint32_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(uint32_t, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            uint32_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (uint32_t) -1;
        }
    } else {
        uint32_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (uint32_t) -1;
        val = __Pyx_PyInt_As_uint32_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
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;
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int8_t(int8_t value) {
    const int8_t neg_one = (int8_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int8_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int8_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int8_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(int8_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int8_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int8_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint8_t(uint8_t value) {
    const uint8_t neg_one = (uint8_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint8_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint8_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint8_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(uint8_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint8_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint8_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int16_t(int16_t value) {
    const int16_t neg_one = (int16_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int16_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int16_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int16_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(int16_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int16_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int16_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint16_t(uint16_t value) {
    const uint16_t neg_one = (uint16_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint16_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint16_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint16_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(uint16_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint16_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint16_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int32_t(int32_t value) {
    const int32_t neg_one = (int32_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int32_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int32_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int32_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(int32_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int32_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int32_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) {
    const uint32_t neg_one = (uint32_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint32_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint32_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint32_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(uint32_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint32_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint32_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(long) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) {
    const size_t neg_one = (size_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(size_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (size_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(size_t, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(size_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(size_t, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(size_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(size_t, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(size_t,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(size_t, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(size_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(size_t, long, PyLong_AsLong(x))
            } else if (sizeof(size_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(size_t, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            size_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (size_t) -1;
        }
    } else {
        size_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (size_t) -1;
        val = __Pyx_PyInt_As_size_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to size_t");
    return (size_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to size_t");
    return (size_t) -1;
}

static CYTHON_INLINE int64_t __Pyx_PyInt_As_int64_t(PyObject *x) {
    const int64_t neg_one = (int64_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int64_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int64_t, long, PyInt_AS_LONG(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_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(int64_t, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(int64_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(int64_t, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(int64_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(int64_t, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(int64_t,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(int64_t, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(int64_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(int64_t, long, PyLong_AsLong(x))
            } else if (sizeof(int64_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(int64_t, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int64_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int64_t) -1;
        }
    } else {
        int64_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (int64_t) -1;
        val = __Pyx_PyInt_As_int64_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
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;
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_As_PY_LONG_LONG(PyObject *x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(PY_LONG_LONG) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (PY_LONG_LONG) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(PY_LONG_LONG) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long, PyLong_AsLong(x))
            } else if (sizeof(PY_LONG_LONG) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(PY_LONG_LONG, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            PY_LONG_LONG val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (PY_LONG_LONG) -1;
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG) -1;
        val = __Pyx_PyInt_As_PY_LONG_LONG(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to PY_LONG_LONG");
    return (PY_LONG_LONG) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to PY_LONG_LONG");
    return (PY_LONG_LONG) -1;
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_PY_LONG_LONG(PY_LONG_LONG value) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(PY_LONG_LONG) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(PY_LONG_LONG) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(PY_LONG_LONG) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(PY_LONG_LONG) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(PY_LONG_LONG),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int64_t(int64_t value) {
    const int64_t neg_one = (int64_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int64_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int64_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int64_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(int64_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int64_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int64_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint64_t(uint64_t value) {
    const uint64_t neg_one = (uint64_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint64_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint64_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(uint64_t) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(uint64_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint64_t) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(uint64_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE uint16_t __Pyx_PyInt_As_uint16_t(PyObject *x) {
    const uint16_t neg_one = (uint16_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(uint16_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(uint16_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (uint16_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint16_t, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(uint16_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(uint16_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(uint16_t, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint16_t,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(uint16_t, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(uint16_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(uint16_t, long, PyLong_AsLong(x))
            } else if (sizeof(uint16_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(uint16_t, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            uint16_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (uint16_t) -1;
        }
    } else {
        uint16_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (uint16_t) -1;
        val = __Pyx_PyInt_As_uint16_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to uint16_t");
    return (uint16_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to uint16_t");
    return (uint16_t) -1;
}

static CYTHON_INLINE int32_t __Pyx_PyInt_As_int32_t(PyObject *x) {
    const int32_t neg_one = (int32_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int32_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int32_t, long, PyInt_AS_LONG(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_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(int32_t, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(int32_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(int32_t, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(int32_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(int32_t, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(int32_t,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(int32_t, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(int32_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(int32_t, long, PyLong_AsLong(x))
            } else if (sizeof(int32_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(int32_t, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int32_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int32_t) -1;
        }
    } else {
        int32_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (int32_t) -1;
        val = __Pyx_PyInt_As_int32_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
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;
}

static CYTHON_INLINE uint8_t __Pyx_PyInt_As_uint8_t(PyObject *x) {
    const uint8_t neg_one = (uint8_t) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(uint8_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(uint8_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (uint8_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint8_t, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(uint8_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(uint8_t, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(uint8_t) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(uint8_t, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(uint8_t,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(uint8_t, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(uint8_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(uint8_t, long, PyLong_AsLong(x))
            } else if (sizeof(uint8_t) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(uint8_t, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            uint8_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (uint8_t) -1;
        }
    } else {
        uint8_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (uint8_t) -1;
        val = __Pyx_PyInt_As_uint8_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to uint8_t");
    return (uint8_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to uint8_t");
    return (uint8_t) -1;
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_char(char value) {
    const char neg_one = (char) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(char) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(char) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(char) <= sizeof(unsigned long long)) {
            return PyLong_FromUnsignedLongLong((unsigned long long) value);
        }
    } else {
        if (sizeof(char) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(char) <= sizeof(long long)) {
            return PyLong_FromLongLong((long long) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(char),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(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_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT(long, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(long) <= sizeof(unsigned long long)) {
                __PYX_VERIFY_RETURN_INT(long, unsigned long long, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
 #if CYTHON_USE_PYLONG_INTERNALS
            switch (Py_SIZE(x)) {
                case  0: return 0;
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +(((PyLongObject*)x)->ob_digit[0]));
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) ((PyLongObject*)x)->ob_digit[0]);
            }
 #endif
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT(long, long, PyLong_AsLong(x))
            } else if (sizeof(long) <= sizeof(long long)) {
                __PYX_VERIFY_RETURN_INT(long, long long, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
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;
}

static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
    PyObject* fake_module;
    PyTypeObject* cached_type = NULL;
    fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
    if (!fake_module) return NULL;
    Py_INCREF(fake_module);
    cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
    if (cached_type) {
        if (!PyType_Check((PyObject*)cached_type)) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s is not a type object",
                type->tp_name);
            goto bad;
        }
        if (cached_type->tp_basicsize != type->tp_basicsize) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s has the wrong size, try recompiling",
                type->tp_name);
            goto bad;
        }
    } else {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
        PyErr_Clear();
        if (PyType_Ready(type) < 0) goto bad;
        if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
            goto bad;
        Py_INCREF(type);
        cached_type = type;
    }
done:
    Py_DECREF(fake_module);
    return cached_type;
bad:
    Py_XDECREF(cached_type);
    cached_type = NULL;
    goto done;
}

static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = *type;
    tstate->exc_value = *value;
    tstate->exc_traceback = *tb;
#else
    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
    PyErr_SetExcInfo(*type, *value, *tb);
#endif
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}

static PyObject *__Pyx_Generator_Next(PyObject *self);
static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value);
static PyObject *__Pyx_Generator_Close(PyObject *self);
static PyObject *__Pyx_Generator_Throw(PyObject *gen, PyObject *args);
static PyTypeObject *__pyx_GeneratorType = 0;
#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType)
#define __Pyx_Generator_Undelegate(gen) Py_CLEAR((gen)->yieldfrom)
#if 1 || PY_VERSION_HEX < 0x030300B0
static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
    PyObject *et, *ev, *tb;
    PyObject *value = NULL;
    __Pyx_ErrFetch(&et, &ev, &tb);
    if (!et) {
        Py_XDECREF(tb);
        Py_XDECREF(ev);
        Py_INCREF(Py_None);
        *pvalue = Py_None;
        return 0;
    }
    if (unlikely(et != PyExc_StopIteration) &&
            unlikely(!PyErr_GivenExceptionMatches(et, PyExc_StopIteration))) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    if (likely(et == PyExc_StopIteration)) {
        if (likely(!ev) || !PyObject_IsInstance(ev, PyExc_StopIteration)) {
            if (!ev) {
                Py_INCREF(Py_None);
                ev = Py_None;
            }
            Py_XDECREF(tb);
            Py_DECREF(et);
            *pvalue = ev;
            return 0;
        }
    }
    PyErr_NormalizeException(&et, &ev, &tb);
    if (unlikely(!PyObject_IsInstance(ev, PyExc_StopIteration))) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    Py_XDECREF(tb);
    Py_DECREF(et);
#if PY_VERSION_HEX >= 0x030300A0
    value = ((PyStopIterationObject *)ev)->value;
    Py_INCREF(value);
    Py_DECREF(ev);
#else
    {
        PyObject* args = PyObject_GetAttr(ev, __pyx_n_s_args);
        Py_DECREF(ev);
        if (likely(args)) {
            value = PyObject_GetItem(args, 0);
            Py_DECREF(args);
        }
        if (unlikely(!value)) {
            __Pyx_ErrRestore(NULL, NULL, NULL);
            Py_INCREF(Py_None);
            value = Py_None;
        }
    }
#endif
    *pvalue = value;
    return 0;
}
#endif
static CYTHON_INLINE
void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) {
    PyObject *exc_type = self->exc_type;
    PyObject *exc_value = self->exc_value;
    PyObject *exc_traceback = self->exc_traceback;
    self->exc_type = NULL;
    self->exc_value = NULL;
    self->exc_traceback = NULL;
    Py_XDECREF(exc_type);
    Py_XDECREF(exc_value);
    Py_XDECREF(exc_traceback);
}
static CYTHON_INLINE
int __Pyx_Generator_CheckRunning(__pyx_GeneratorObject *gen) {
    if (unlikely(gen->is_running)) {
        PyErr_SetString(PyExc_ValueError,
                        "generator already executing");
        return 1;
    }
    return 0;
}
static CYTHON_INLINE
PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) {
    PyObject *retval;
    assert(!self->is_running);
    if (unlikely(self->resume_label == 0)) {
        if (unlikely(value && value != Py_None)) {
            PyErr_SetString(PyExc_TypeError,
                            "can't send non-None value to a "
                            "just-started generator");
            return NULL;
        }
    }
    if (unlikely(self->resume_label == -1)) {
        PyErr_SetNone(PyExc_StopIteration);
        return NULL;
    }
    if (value) {
#if CYTHON_COMPILING_IN_PYPY
#else
        if (self->exc_traceback) {
            PyThreadState *tstate = PyThreadState_GET();
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_XINCREF(tstate->frame);
            assert(f->f_back == NULL);
            f->f_back = tstate->frame;
        }
#endif
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
    } else {
        __Pyx_Generator_ExceptionClear(self);
    }
    self->is_running = 1;
    retval = self->body((PyObject *) self, value);
    self->is_running = 0;
    if (retval) {
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
#if CYTHON_COMPILING_IN_PYPY
#else
        if (self->exc_traceback) {
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_CLEAR(f->f_back);
        }
#endif
    } else {
        __Pyx_Generator_ExceptionClear(self);
    }
    return retval;
}
static CYTHON_INLINE
PyObject *__Pyx_Generator_FinishDelegation(__pyx_GeneratorObject *gen) {
    PyObject *ret;
    PyObject *val = NULL;
    __Pyx_Generator_Undelegate(gen);
    __Pyx_PyGen_FetchStopIterationValue(&val);
    ret = __Pyx_Generator_SendEx(gen, val);
    Py_XDECREF(val);
    return ret;
}
static PyObject *__Pyx_Generator_Next(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        ret = Py_TYPE(yf)->tp_iternext(yf);
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        return __Pyx_Generator_FinishDelegation(gen);
    }
    return __Pyx_Generator_SendEx(gen, Py_None);
}
static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Send(yf, value);
        } else {
            if (value == Py_None)
                ret = PyIter_Next(yf);
            else
                ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value);
        }
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        return __Pyx_Generator_FinishDelegation(gen);
    }
    return __Pyx_Generator_SendEx(gen, value);
}
static int __Pyx_Generator_CloseIter(__pyx_GeneratorObject *gen, PyObject *yf) {
    PyObject *retval = NULL;
    int err = 0;
    if (__Pyx_Generator_CheckExact(yf)) {
        retval = __Pyx_Generator_Close(yf);
        if (!retval)
            return -1;
    } else {
        PyObject *meth;
        gen->is_running = 1;
        meth = PyObject_GetAttr(yf, __pyx_n_s_close);
        if (unlikely(!meth)) {
            if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                PyErr_WriteUnraisable(yf);
            }
            PyErr_Clear();
        } else {
            retval = PyObject_CallFunction(meth, NULL);
            Py_DECREF(meth);
            if (!retval)
                err = -1;
        }
        gen->is_running = 0;
    }
    Py_XDECREF(retval);
    return err;
}
static PyObject *__Pyx_Generator_Close(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject *retval, *raised_exception;
    PyObject *yf = gen->yieldfrom;
    int err = 0;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        Py_INCREF(yf);
        err = __Pyx_Generator_CloseIter(gen, yf);
        __Pyx_Generator_Undelegate(gen);
        Py_DECREF(yf);
    }
    if (err == 0)
        PyErr_SetNone(PyExc_GeneratorExit);
    retval = __Pyx_Generator_SendEx(gen, NULL);
    if (retval) {
        Py_DECREF(retval);
        PyErr_SetString(PyExc_RuntimeError,
                        "generator ignored GeneratorExit");
        return NULL;
    }
    raised_exception = PyErr_Occurred();
    if (!raised_exception
        || raised_exception == PyExc_StopIteration
        || raised_exception == PyExc_GeneratorExit
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit)
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration))
    {
        if (raised_exception) PyErr_Clear();
        Py_INCREF(Py_None);
        return Py_None;
    }
    return NULL;
}
static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject *typ;
    PyObject *tb = NULL;
    PyObject *val = NULL;
    PyObject *yf = gen->yieldfrom;
    if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
        return NULL;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        Py_INCREF(yf);
        if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) {
            int err = __Pyx_Generator_CloseIter(gen, yf);
            Py_DECREF(yf);
            __Pyx_Generator_Undelegate(gen);
            if (err < 0)
                return __Pyx_Generator_SendEx(gen, NULL);
            goto throw_here;
        }
        gen->is_running = 1;
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Throw(yf, args);
        } else {
            PyObject *meth = PyObject_GetAttr(yf, __pyx_n_s_throw);
            if (unlikely(!meth)) {
                Py_DECREF(yf);
                if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                    gen->is_running = 0;
                    return NULL;
                }
                PyErr_Clear();
                __Pyx_Generator_Undelegate(gen);
                gen->is_running = 0;
                goto throw_here;
            }
            ret = PyObject_CallObject(meth, args);
            Py_DECREF(meth);
        }
        gen->is_running = 0;
        Py_DECREF(yf);
        if (!ret) {
            ret = __Pyx_Generator_FinishDelegation(gen);
        }
        return ret;
    }
throw_here:
    __Pyx_Raise(typ, val, tb, NULL);
    return __Pyx_Generator_SendEx(gen, NULL);
}
static int __Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    Py_VISIT(gen->closure);
    Py_VISIT(gen->classobj);
    Py_VISIT(gen->yieldfrom);
    Py_VISIT(gen->exc_type);
    Py_VISIT(gen->exc_value);
    Py_VISIT(gen->exc_traceback);
    return 0;
}
static int __Pyx_Generator_clear(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    Py_CLEAR(gen->closure);
    Py_CLEAR(gen->classobj);
    Py_CLEAR(gen->yieldfrom);
    Py_CLEAR(gen->exc_type);
    Py_CLEAR(gen->exc_value);
    Py_CLEAR(gen->exc_traceback);
    Py_CLEAR(gen->gi_name);
    Py_CLEAR(gen->gi_qualname);
    return 0;
}
static void __Pyx_Generator_dealloc(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject_GC_UnTrack(gen);
    if (gen->gi_weakreflist != NULL)
        PyObject_ClearWeakRefs(self);
    if (gen->resume_label > 0) {
        PyObject_GC_Track(self);
#if PY_VERSION_HEX >= 0x030400a1
        if (PyObject_CallFinalizerFromDealloc(self))
#else
        Py_TYPE(gen)->tp_del(self);
        if (self->ob_refcnt > 0)
#endif
        {
            return;
        }
        PyObject_GC_UnTrack(self);
    }
    __Pyx_Generator_clear(self);
    PyObject_GC_Del(gen);
}
static void __Pyx_Generator_del(PyObject *self) {
    PyObject *res;
    PyObject *error_type, *error_value, *error_traceback;
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    if (gen->resume_label <= 0)
        return ;
#if PY_VERSION_HEX < 0x030400a1
    assert(self->ob_refcnt == 0);
    self->ob_refcnt = 1;
#endif
    __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
    res = __Pyx_Generator_Close(self);
    if (res == NULL)
        PyErr_WriteUnraisable(self);
    else
        Py_DECREF(res);
    __Pyx_ErrRestore(error_type, error_value, error_traceback);
#if PY_VERSION_HEX < 0x030400a1
    assert(self->ob_refcnt > 0);
    if (--self->ob_refcnt == 0) {
        return;
    }
    {
        Py_ssize_t refcnt = self->ob_refcnt;
        _Py_NewReference(self);
        self->ob_refcnt = refcnt;
    }
#if CYTHON_COMPILING_IN_CPYTHON
    assert(PyType_IS_GC(self->ob_type) &&
           _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
    _Py_DEC_REFTOTAL;
#endif
#ifdef COUNT_ALLOCS
    --Py_TYPE(self)->tp_frees;
    --Py_TYPE(self)->tp_allocs;
#endif
#endif
}
static PyObject *
__Pyx_Generator_get_name(__pyx_GeneratorObject *self)
{
    Py_INCREF(self->gi_name);
    return self->gi_name;
}
static int
__Pyx_Generator_set_name(__pyx_GeneratorObject *self, PyObject *value)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
        PyErr_SetString(PyExc_TypeError,
                        "__name__ must be set to a string object");
        return -1;
    }
    tmp = self->gi_name;
    Py_INCREF(value);
    self->gi_name = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_Generator_get_qualname(__pyx_GeneratorObject *self)
{
    Py_INCREF(self->gi_qualname);
    return self->gi_qualname;
}
static int
__Pyx_Generator_set_qualname(__pyx_GeneratorObject *self, PyObject *value)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
        PyErr_SetString(PyExc_TypeError,
                        "__qualname__ must be set to a string object");
        return -1;
    }
    tmp = self->gi_qualname;
    Py_INCREF(value);
    self->gi_qualname = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyGetSetDef __pyx_Generator_getsets[] = {
    {(char *) "__name__", (getter)__Pyx_Generator_get_name, (setter)__Pyx_Generator_set_name,
     (char*) PyDoc_STR("name of the generator"), 0},
    {(char *) "__qualname__", (getter)__Pyx_Generator_get_qualname, (setter)__Pyx_Generator_set_qualname,
     (char*) PyDoc_STR("qualified name of the generator"), 0},
    {0, 0, 0, 0, 0}
};
static PyMemberDef __pyx_Generator_memberlist[] = {
    {(char *) "gi_running", T_BOOL, offsetof(__pyx_GeneratorObject, is_running), READONLY, NULL},
    {0, 0, 0, 0, 0}
};
static PyMethodDef __pyx_Generator_methods[] = {
    {"send", (PyCFunction) __Pyx_Generator_Send, METH_O, 0},
    {"throw", (PyCFunction) __Pyx_Generator_Throw, METH_VARARGS, 0},
    {"close", (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0},
    {0, 0, 0, 0}
};
static PyTypeObject __pyx_GeneratorType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    "generator",
    sizeof(__pyx_GeneratorObject),
    0,
    (destructor) __Pyx_Generator_dealloc,
    0,
    0,
    0,
#if PY_MAJOR_VERSION < 3
    0,
#else
    0,
#endif
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE,
    0,
    (traverseproc) __Pyx_Generator_traverse,
    0,
    0,
    offsetof(__pyx_GeneratorObject, gi_weakreflist),
    0,
    (iternextfunc) __Pyx_Generator_Next,
    __pyx_Generator_methods,
    __pyx_Generator_memberlist,
    __pyx_Generator_getsets,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
#if PY_VERSION_HEX >= 0x030400a1
    0,
#else
    __Pyx_Generator_del,
#endif
    0,
#if PY_VERSION_HEX >= 0x030400a1
    __Pyx_Generator_del,
#endif
};
static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body,
                                                  PyObject *closure, PyObject *name, PyObject *qualname) {
    __pyx_GeneratorObject *gen =
        PyObject_GC_New(__pyx_GeneratorObject, &__pyx_GeneratorType_type);
    if (gen == NULL)
        return NULL;
    gen->body = body;
    gen->closure = closure;
    Py_XINCREF(closure);
    gen->is_running = 0;
    gen->resume_label = 0;
    gen->classobj = NULL;
    gen->yieldfrom = NULL;
    gen->exc_type = NULL;
    gen->exc_value = NULL;
    gen->exc_traceback = NULL;
    gen->gi_weakreflist = NULL;
    Py_XINCREF(qualname);
    gen->gi_qualname = qualname;
    Py_XINCREF(name);
    gen->gi_name = name;
    PyObject_GC_Track(gen);
    return gen;
}
static int __pyx_Generator_init(void) {
    __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr;
    __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
    __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type);
    if (__pyx_GeneratorType == NULL) {
        return -1;
    }
    return 0;
}

static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    py_name = __Pyx_PyIdentifier_FromString(class_name);
    if (!py_name)
        goto bad;
    result = PyObject_GetAttr(py_module, py_name);
    Py_DECREF(py_name);
    py_name = 0;
    Py_DECREF(py_module);
    py_module = 0;
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if (!strict && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility",
            module_name, class_name);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s has the wrong size, try recompiling",
            module_name, class_name);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

static int __Pyx_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;
        ++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 char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
#if PY_VERSION_HEX < 0x03030000
        char* defenc_c;
        PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
        if (!defenc) return NULL;
        defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        {
            char* end = defenc_c + PyBytes_GET_SIZE(defenc);
            char* c;
            for (c = defenc_c; c < end; c++) {
                if ((unsigned char) (*c) >= 128) {
                    PyUnicode_AsASCIIString(o);
                    return NULL;
                }
            }
        }
#endif
        *length = PyBytes_GET_SIZE(defenc);
        return defenc_c;
#else
        if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (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
    } else
#endif
#if !CYTHON_COMPILING_IN_PYPY
    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 PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%.4s__ returned non-%.4s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b)))
      return PyInt_AS_LONG(b);
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
     #if CYTHON_USE_PYLONG_INTERNALS
       switch (Py_SIZE(b)) {
       case -1: return -(sdigit)((PyLongObject*)b)->ob_digit[0];
       case  0: return 0;
       case  1: return ((PyLongObject*)b)->ob_digit[0];
       }
     #endif
    #endif
    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 PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
