/* Generated by Cython 0.17.4 on Fri Jan 25 10:34:03 2013 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02040000
    #error Cython requires Python 2.4+.
#else
#include <stddef.h> /* For offsetof */
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#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 PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PY_FORMAT_SIZE_T ""
  #define CYTHON_FORMAT_SSIZE_T ""
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)   __Pyx_PyInt_AsInt(o)
  #define PyNumber_Index(o)    ((PyNumber_Check(o) && !PyFloat_Check(o)) ? PyNumber_Int(o) : \
                                (PyErr_Format(PyExc_TypeError, \
                                              "expected index value, got %.200s", Py_TYPE(o)->tp_name), \
                                 (PyObject*)0))
  #define __Pyx_PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && \
                                  !PyComplex_Check(o))
  #define PyIndex_Check __Pyx_PyIndex_Check
  #define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
  #define __PYX_BUILD_PY_SSIZE_T "i"
#else
  #define __PYX_BUILD_PY_SSIZE_T "n"
  #define CYTHON_FORMAT_SSIZE_T "z"
  #define __Pyx_PyIndex_Check PyIndex_Check
#endif
#if PY_VERSION_HEX < 0x02060000
  #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
  #define Py_TYPE(ob)   (((PyObject*)(ob))->ob_type)
  #define Py_SIZE(ob)   (((PyVarObject*)(ob))->ob_size)
  #define PyVarObject_HEAD_INIT(type, size) \
          PyObject_HEAD_INIT(type) size,
  #define PyType_Modified(t)
  typedef struct {
     void *buf;
     PyObject *obj;
     Py_ssize_t len;
     Py_ssize_t itemsize;
     int readonly;
     int ndim;
     char *format;
     Py_ssize_t *shape;
     Py_ssize_t *strides;
     Py_ssize_t *suboffsets;
     void *internal;
  } Py_buffer;
  #define PyBUF_SIMPLE 0
  #define PyBUF_WRITABLE 0x0001
  #define PyBUF_FORMAT 0x0004
  #define PyBUF_ND 0x0008
  #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
  #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
  #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
  #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
  #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
  #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_FORMAT | PyBUF_WRITABLE)
  #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_FORMAT | PyBUF_WRITABLE)
  typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
  typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
#endif
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) \
          PyCode_New(a, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#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)
#endif
#if PY_MAJOR_VERSION < 3 && PY_MINOR_VERSION < 6
  #define PyUnicode_FromString(s) PyUnicode_Decode(s, strlen(s), "UTF-8", "strict")
#endif
#if PY_MAJOR_VERSION >= 3
  #define Py_TPFLAGS_CHECKTYPES 0
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#if (PY_VERSION_HEX < 0x02060000) || (PY_MAJOR_VERSION >= 3)
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#if PY_VERSION_HEX > 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_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_READ(k, d, i)   ((k=k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif
#if PY_VERSION_HEX < 0x02060000
  #define PyBytesObject                PyStringObject
  #define PyBytes_Type                 PyString_Type
  #define PyBytes_Check                PyString_Check
  #define PyBytes_CheckExact           PyString_CheckExact
  #define PyBytes_FromString           PyString_FromString
  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
  #define PyBytes_FromFormat           PyString_FromFormat
  #define PyBytes_DecodeEscape         PyString_DecodeEscape
  #define PyBytes_AsString             PyString_AsString
  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
  #define PyBytes_Size                 PyString_Size
  #define PyBytes_AS_STRING            PyString_AS_STRING
  #define PyBytes_GET_SIZE             PyString_GET_SIZE
  #define PyBytes_Repr                 PyString_Repr
  #define PyBytes_Concat               PyString_Concat
  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
#endif
#if PY_VERSION_HEX < 0x02060000
  #define PySet_Check(obj)             PyObject_TypeCheck(obj, &PySet_Type)
  #define PyFrozenSet_Check(obj)       PyObject_TypeCheck(obj, &PyFrozenSet_Type)
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_VERSION_HEX < 0x03020000
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if (PY_MAJOR_VERSION < 3) || (PY_VERSION_HEX >= 0x03010300)
  #define __Pyx_PySequence_GetSlice(obj, a, b) PySequence_GetSlice(obj, a, b)
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) PySequence_SetSlice(obj, a, b, value)
  #define __Pyx_PySequence_DelSlice(obj, a, b) PySequence_DelSlice(obj, a, b)
#else
  #define __Pyx_PySequence_GetSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), (PyObject*)0) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_GetSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object is unsliceable", (obj)->ob_type->tp_name), (PyObject*)0)))
  #define __Pyx_PySequence_SetSlice(obj, a, b, value) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_SetSlice(obj, a, b, value)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice assignment", (obj)->ob_type->tp_name), -1)))
  #define __Pyx_PySequence_DelSlice(obj, a, b) (unlikely(!(obj)) ? \
        (PyErr_SetString(PyExc_SystemError, "null argument to internal routine"), -1) : \
        (likely((obj)->ob_type->tp_as_mapping) ? (PySequence_DelSlice(obj, a, b)) : \
            (PyErr_Format(PyExc_TypeError, "'%.200s' object doesn't support slice deletion", (obj)->ob_type->tp_name), -1)))
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),((char *)(n)))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),((char *)(n)),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),((char *)(n)))
#else
  #define __Pyx_GetAttrString(o,n)   PyObject_GetAttrString((o),(n))
  #define __Pyx_SetAttrString(o,n,a) PyObject_SetAttrString((o),(n),(a))
  #define __Pyx_DelAttrString(o,n)   PyObject_DelAttrString((o),(n))
#endif
#if PY_VERSION_HEX < 0x02050000
  #define __Pyx_NAMESTR(n) ((char *)(n))
  #define __Pyx_DOCSTR(n)  ((char *)(n))
#else
  #define __Pyx_NAMESTR(n) (n)
  #define __Pyx_DOCSTR(n)  (n)
#endif


#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__pysamstats
#define __PYX_HAVE_API__pysamstats
#include "stdio.h"
#include "stdlib.h"
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
#include "stdint.h"
#include "math.h"
#include "pythread.h"
#include "string.h"
#include "ctype.h"
#include "unistd.h"
#include "razf.h"
#include "bam.h"
#include "sam.h"
#include "faidx.h"
#include "pysam_util.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif


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

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

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


/* Type Conversion Predeclarations */

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

#define __Pyx_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);
static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*);

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

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

#if !defined(CYTHON_CCOMPLEX)
  #if defined(__cplusplus)
    #define CYTHON_CCOMPLEX 1
  #elif defined(_Complex_I)
    #define CYTHON_CCOMPLEX 1
  #else
    #define CYTHON_CCOMPLEX 0
  #endif
#endif
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    #include <complex>
  #else
    #include <complex.h>
  #endif
#endif
#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__)
  #undef _Complex_I
  #define _Complex_I 1.0fj
#endif


static const char *__pyx_f[] = {
  "pysamstats.pyx",
  "numpy.pxd",
  "type.pxd",
  "bool.pxd",
  "complex.pxd",
  "csamtools.pxd",
};

/* "numpy.pxd":723
 * # in Cython to enable them only on the right systems.
 * 
 * ctypedef npy_int8       int8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 */
typedef npy_int8 __pyx_t_5numpy_int8_t;

/* "numpy.pxd":724
 * 
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t
 */
typedef npy_int16 __pyx_t_5numpy_int16_t;

/* "numpy.pxd":725
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int64      int64_t
 * #ctypedef npy_int96      int96_t
 */
typedef npy_int32 __pyx_t_5numpy_int32_t;

/* "numpy.pxd":726
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_int96      int96_t
 * #ctypedef npy_int128     int128_t
 */
typedef npy_int64 __pyx_t_5numpy_int64_t;

/* "numpy.pxd":730
 * #ctypedef npy_int128     int128_t
 * 
 * ctypedef npy_uint8      uint8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 */
typedef npy_uint8 __pyx_t_5numpy_uint8_t;

/* "numpy.pxd":731
 * 
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t
 */
typedef npy_uint16 __pyx_t_5numpy_uint16_t;

/* "numpy.pxd":732
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint64     uint64_t
 * #ctypedef npy_uint96     uint96_t
 */
typedef npy_uint32 __pyx_t_5numpy_uint32_t;

/* "numpy.pxd":733
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_uint96     uint96_t
 * #ctypedef npy_uint128    uint128_t
 */
typedef npy_uint64 __pyx_t_5numpy_uint64_t;

/* "numpy.pxd":737
 * #ctypedef npy_uint128    uint128_t
 * 
 * ctypedef npy_float32    float32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_float64    float64_t
 * #ctypedef npy_float80    float80_t
 */
typedef npy_float32 __pyx_t_5numpy_float32_t;

/* "numpy.pxd":738
 * 
 * ctypedef npy_float32    float32_t
 * ctypedef npy_float64    float64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_float80    float80_t
 * #ctypedef npy_float128   float128_t
 */
typedef npy_float64 __pyx_t_5numpy_float64_t;

/* "numpy.pxd":747
 * # The int types are mapped a bit surprising --
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t
 */
typedef npy_long __pyx_t_5numpy_int_t;

/* "numpy.pxd":748
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   longlong_t
 * 
 */
typedef npy_longlong __pyx_t_5numpy_long_t;

/* "numpy.pxd":749
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_ulong      uint_t
 */
typedef npy_longlong __pyx_t_5numpy_longlong_t;

/* "numpy.pxd":751
 * ctypedef npy_longlong   longlong_t
 * 
 * ctypedef npy_ulong      uint_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t
 */
typedef npy_ulong __pyx_t_5numpy_uint_t;

/* "numpy.pxd":752
 * 
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 */
typedef npy_ulonglong __pyx_t_5numpy_ulong_t;

/* "numpy.pxd":753
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_intp       intp_t
 */
typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t;

/* "numpy.pxd":755
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 * ctypedef npy_intp       intp_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uintp      uintp_t
 * 
 */
typedef npy_intp __pyx_t_5numpy_intp_t;

/* "numpy.pxd":756
 * 
 * ctypedef npy_intp       intp_t
 * ctypedef npy_uintp      uintp_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_double     float_t
 */
typedef npy_uintp __pyx_t_5numpy_uintp_t;

/* "numpy.pxd":758
 * ctypedef npy_uintp      uintp_t
 * 
 * ctypedef npy_double     float_t             # <<<<<<<<<<<<<<
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t
 */
typedef npy_double __pyx_t_5numpy_float_t;

/* "numpy.pxd":759
 * 
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longdouble longdouble_t
 * 
 */
typedef npy_double __pyx_t_5numpy_double_t;

/* "numpy.pxd":760
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cfloat      cfloat_t
 */
typedef npy_longdouble __pyx_t_5numpy_longdouble_t;
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< float > __pyx_t_float_complex;
  #else
    typedef float _Complex __pyx_t_float_complex;
  #endif
#else
    typedef struct { float real, imag; } __pyx_t_float_complex;
#endif

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< double > __pyx_t_double_complex;
  #else
    typedef double _Complex __pyx_t_double_complex;
  #endif
#else
    typedef struct { double real, imag; } __pyx_t_double_complex;
#endif


/*--- Type declarations ---*/
struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed;
struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq;
struct __pyx_obj_5pysam_9csamtools_Fastafile;
struct __pyx_obj_5pysam_9csamtools_IteratorRow;
struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion;
struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc;
struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand;
struct __pyx_obj_5pysam_9csamtools_IndexedReads;
struct __pyx_obj_5pysam_9csamtools_IteratorColumn;
struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection;
struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand;
struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand;
struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc;
struct __pyx_obj_5pysam_9csamtools_IteratorColumnRegion;
struct __pyx_obj_5pysam_9csamtools_IteratorRowAll;
struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation;
struct __pyx_obj_5pysam_9csamtools_PileupProxy;
struct __pyx_obj_5pysam_9csamtools_PileupRead;
struct __pyx_obj_5pysam_9csamtools_IteratorRowAllRefs;
struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand;
struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand;
struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen;
struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr;
struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq;
struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand;
struct __pyx_obj_5pysam_9csamtools_IteratorColumnAllRefs;
struct __pyx_obj_5pysam_9csamtools_Samfile;
struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext;
struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage;
struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand;
struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr;
struct __pyx_obj_5pysam_9csamtools_AlignedRead;
struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext;

/* "numpy.pxd":762
 * ctypedef npy_longdouble longdouble_t
 * 
 * ctypedef npy_cfloat      cfloat_t             # <<<<<<<<<<<<<<
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t
 */
typedef npy_cfloat __pyx_t_5numpy_cfloat_t;

/* "numpy.pxd":763
 * 
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t             # <<<<<<<<<<<<<<
 * ctypedef npy_clongdouble clongdouble_t
 * 
 */
typedef npy_cdouble __pyx_t_5numpy_cdouble_t;

/* "numpy.pxd":764
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cdouble     complex_t
 */
typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t;

/* "numpy.pxd":766
 * ctypedef npy_clongdouble clongdouble_t
 * 
 * ctypedef npy_cdouble     complex_t             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 */
typedef npy_cdouble __pyx_t_5numpy_complex_t;
struct __pyx_t_5pysam_9csamtools___iterdata;
typedef struct __pyx_t_5pysam_9csamtools___iterdata __pyx_t_5pysam_9csamtools___iterdata;
struct __pyx_opt_args_5pysam_9csamtools_14IteratorColumn_setupIteratorData;

/* "pysam/csamtools.pxd":394
 * # Utility types
 * 
 * ctypedef struct __iterdata:             # <<<<<<<<<<<<<<
 *     samfile_t * samfile
 *     bam_iter_t iter
 */
struct __pyx_t_5pysam_9csamtools___iterdata {
  samfile_t *samfile;
  bam_iter_t iter;
  faidx_t *fastafile;
  int tid;
  char *seq;
  int seq_len;
};

/* "pysam/csamtools.pxd":523
 *     cdef char * getSequence( self )
 *     cdef setMask( self, mask )
 *     cdef setupIteratorData( self,             # <<<<<<<<<<<<<<
 *                             int tid,
 *                             int start,
 */
struct __pyx_opt_args_5pysam_9csamtools_14IteratorColumn_setupIteratorData {
  int __pyx_n;
  int reopen;
};
struct __pyx_opt_args_10pysamstats_construct_rec_coverage;
struct __pyx_opt_args_10pysamstats_construct_rec_coverage_strand;
struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext;
struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext_strand;
struct __pyx_opt_args_10pysamstats_construct_rec_variation;
struct __pyx_t_10pysamstats_CountPpStrand;
struct __pyx_opt_args_10pysamstats_construct_rec_variation_strand;
struct __pyx_opt_args_10pysamstats_construct_rec_tlen;
struct __pyx_opt_args_10pysamstats_construct_rec_tlen_strand;
struct __pyx_opt_args_10pysamstats_construct_rec_mapq;
struct __pyx_opt_args_10pysamstats_construct_rec_mapq_strand;
struct __pyx_opt_args_10pysamstats_construct_rec_baseq;
struct __pyx_opt_args_10pysamstats_construct_rec_baseq_strand;
struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext;
struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext_strand;

/* "pysamstats.pyx":65
 * 
 * 
 * cpdef object construct_rec_coverage(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
struct __pyx_opt_args_10pysamstats_construct_rec_coverage {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":116
 * 
 * 
 * cpdef object construct_rec_coverage_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
struct __pyx_opt_args_10pysamstats_construct_rec_coverage_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":187
 * 
 * 
 * cpdef object construct_rec_coverage_ext(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":280
 * 
 * 
 * cpdef object construct_rec_coverage_ext_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":455
 * 
 * 
 * cpdef object construct_rec_variation(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                      PileupProxy col, bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats_construct_rec_variation {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":589
 * 
 * 
 * cdef struct CountPpStrand:             # <<<<<<<<<<<<<<
 *     unsigned int all, pp, fwd, rev, pp_fwd, pp_rev
 * 
 */
struct __pyx_t_10pysamstats_CountPpStrand {
  unsigned int all;
  unsigned int pp;
  unsigned int fwd;
  unsigned int rev;
  unsigned int pp_fwd;
  unsigned int pp_rev;
};

/* "pysamstats.pyx":611
 * 
 * 
 * cpdef object construct_rec_variation_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                             PileupProxy col, bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats_construct_rec_variation_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":724
 * 
 * 
 * cpdef object construct_rec_tlen(Samfile samfile, PileupProxy col,             # <<<<<<<<<<<<<<
 *                                 bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats_construct_rec_tlen {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":859
 * 
 * 
 * cpdef object construct_rec_tlen_strand(Samfile samfile, PileupProxy col,             # <<<<<<<<<<<<<<
 *                                        bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats_construct_rec_tlen_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1121
 * 
 * 
 * cpdef object construct_rec_mapq(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
struct __pyx_opt_args_10pysamstats_construct_rec_mapq {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1211
 * 
 * 
 * cpdef object construct_rec_mapq_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
struct __pyx_opt_args_10pysamstats_construct_rec_mapq_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1395
 * 
 * 
 * cpdef object construct_rec_baseq(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
struct __pyx_opt_args_10pysamstats_construct_rec_baseq {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1471
 * 
 * 
 * cpdef object construct_rec_baseq_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
struct __pyx_opt_args_10pysamstats_construct_rec_baseq_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1600
 * 
 * 
 * cpdef object construct_rec_baseq_ext(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                      PileupProxy col, bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1718
 * 
 * 
 * cpdef object construct_rec_baseq_ext_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                             PileupProxy col, bint one_based=False):
 * 
 */
struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext_strand {
  int __pyx_n;
  int one_based;
};

/* "pysamstats.pyx":1937
 * 
 * 
 * def stat_coverage_normed(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 * 
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed {
  PyObject_HEAD
  PyObject *__pyx_v_a;
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_dp;
  PyObject *__pyx_v_dp_mean;
  PyObject *__pyx_v_dp_median;
  PyObject *__pyx_v_dp_normed_mean;
  PyObject *__pyx_v_dp_normed_median;
  PyObject *__pyx_v_dp_percentile;
  PyObject *__pyx_v_dp_percentiles;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_genexpr;
  PyObject *__pyx_v_it;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  PyObject *__pyx_v_pos;
  long __pyx_v_q;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":1191
 * 
 * 
 * def stat_mapq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysam/csamtools.pxd":408
 * # Note: need to declare all C fields and methods here
 * #
 * cdef class Fastafile:             # <<<<<<<<<<<<<<
 *     cdef char * _filename
 *     # pointer to fastafile
 */
struct __pyx_obj_5pysam_9csamtools_Fastafile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_9csamtools_Fastafile *__pyx_vtab;
  char *_filename;
  faidx_t *fastafile;
};


/* "pysam/csamtools.pxd":464
 *     cdef uint32_t _is_tail
 * 
 * cdef class IteratorRow:             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_9csamtools_IteratorRow {
  PyObject_HEAD
};


/* "pysam/csamtools.pxd":467
 *     pass
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam_iter_t             iter # iterator state object
 *     cdef bam1_t *               b
 */
struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion {
  struct __pyx_obj_5pysam_9csamtools_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion *__pyx_vtab;
  bam_iter_t iter;
  bam1_t *b;
  int retval;
  struct __pyx_obj_5pysam_9csamtools_Samfile *samfile;
  samfile_t *fp;
  int owns_samfile;
};


/* "pysamstats.pyx":2024
 * 
 * 
 * def stat_coverage_normed_gc(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 * 
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc {
  PyObject_HEAD
  PyObject *__pyx_v_a;
  PyObject *__pyx_v_b;
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_dp;
  PyObject *__pyx_v_dp_mean;
  PyObject *__pyx_v_dp_mean_bygc;
  PyObject *__pyx_v_dp_median;
  PyObject *__pyx_v_dp_median_bygc;
  PyObject *__pyx_v_dp_normed_mean;
  PyObject *__pyx_v_dp_normed_mean_bygc;
  PyObject *__pyx_v_dp_normed_median;
  PyObject *__pyx_v_dp_normed_median_bygc;
  PyObject *__pyx_v_dp_percentile;
  PyObject *__pyx_v_dp_percentile_bygc;
  PyObject *__pyx_v_dp_percentiles;
  PyObject *__pyx_v_dp_percentiles_bygc;
  PyObject *__pyx_v_end;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile;
  PyObject *__pyx_v_flt;
  PyObject *__pyx_v_gc;
  PyObject *__pyx_v_genexpr;
  PyObject *__pyx_v_it;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  long __pyx_v_q;
  PyObject *__pyx_v_rec;
  PyObject *__pyx_v_recs;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":1579
 * 
 * 
 * def stat_baseq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysam/csamtools.pxd":539
 *     pass
 * 
 * cdef class IndexedReads:             # <<<<<<<<<<<<<<
 *     cdef Samfile samfile
 *     cdef samfile_t * fp
 */
struct __pyx_obj_5pysam_9csamtools_IndexedReads {
  PyObject_HEAD
  struct __pyx_obj_5pysam_9csamtools_Samfile *samfile;
  samfile_t *fp;
  PyObject *index;
  int owns_samfile;
};


/* "pysam/csamtools.pxd":504
 *     cdef int cnext(self)
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 * 
 *     # result of the last plbuf_push
 */
struct __pyx_obj_5pysam_9csamtools_IteratorColumn {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumn *__pyx_vtab;
  struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *iter;
  int tid;
  int pos;
  int n_plp;
  int mask;
  const bam_pileup1_t * plp;
  bam_plp_t pileup_iter;
  __pyx_t_5pysam_9csamtools___iterdata iterdata;
  struct __pyx_obj_5pysam_9csamtools_Samfile *samfile;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *fastafile;
  PyObject *stepper;
  int max_depth;
};


/* "pysam/csamtools.pxd":492
 *     cdef IteratorRowRegion rowiter
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam1_t * b
 *     cdef int current_pos
 */
struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection {
  struct __pyx_obj_5pysam_9csamtools_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowSelection *__pyx_vtab;
  bam1_t *b;
  int current_pos;
  samfile_t *fp;
  PyObject *positions;
  int owns_samfile;
};


/* "pysamstats.pyx":169
 * 
 * 
 * def stat_coverage_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":1370
 * 
 * 
 * def stat_mapq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":1978
 * 
 * 
 * def stat_coverage_gc(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                      chrom=None, start=None, end=None, one_based=False,
 *                      gc_window_length=300, gc_window_offset=150, **kwargs):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc {
  PyObject_HEAD
  char __pyx_v_b;
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile;
  int __pyx_v_gc_count;
  PyObject *__pyx_v_gc_percent;
  PyObject *__pyx_v_gc_window_length;
  PyObject *__pyx_v_gc_window_offset;
  Py_ssize_t __pyx_v_i;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  PyObject *__pyx_v_rec;
  PyObject *__pyx_v_ref_window;
  PyObject *__pyx_v_ref_window_end;
  PyObject *__pyx_v_ref_window_start;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  char *__pyx_v_seq;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysam/csamtools.pxd":531
 *     cdef reset( self, tid, start, end )
 * 
 * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
 *     cdef int start
 *     cdef int end
 */
struct __pyx_obj_5pysam_9csamtools_IteratorColumnRegion {
  struct __pyx_obj_5pysam_9csamtools_IteratorColumn __pyx_base;
  int start;
  int end;
  int truncate;
};


/* "pysam/csamtools.pxd":480
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam1_t * b
 *     cdef samfile_t * fp
 */
struct __pyx_obj_5pysam_9csamtools_IteratorRowAll {
  struct __pyx_obj_5pysam_9csamtools_IteratorRow __pyx_base;
  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowAll *__pyx_vtab;
  bam1_t *b;
  samfile_t *fp;
  int owns_samfile;
};


/* "pysamstats.pyx":567
 * 
 * 
 * def stat_variation(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


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


/* "pysam/csamtools.pxd":455
 *     cdef int n_pu
 * 
 * cdef class PileupRead:             # <<<<<<<<<<<<<<
 *     cdef AlignedRead _alignment
 *     cdef int32_t  _qpos
 */
struct __pyx_obj_5pysam_9csamtools_PileupRead {
  PyObject_HEAD
  struct __pyx_obj_5pysam_9csamtools_AlignedRead *_alignment;
  int32_t _qpos;
  int _indel;
  int _level;
  uint32_t _is_del;
  uint32_t _is_head;
  uint32_t _is_tail;
};


/* "pysam/csamtools.pxd":487
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowAllRefs(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef Samfile     samfile
 *     cdef int         tid
 */
struct __pyx_obj_5pysam_9csamtools_IteratorRowAllRefs {
  struct __pyx_obj_5pysam_9csamtools_IteratorRow __pyx_base;
  struct __pyx_obj_5pysam_9csamtools_Samfile *samfile;
  int tid;
  struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *rowiter;
};


/* "pysamstats.pyx":697
 * 
 * 
 * def stat_variation_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":1096
 * 
 * 
 * def stat_tlen_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":839
 * 
 * 
 * def stat_tlen(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":1941
 * 
 *     # first need to load the coverage data into an array, to calculate the median
 *     it = (col.n for col in samfile.pileup(reference=chrom, start=start, end=end))             # <<<<<<<<<<<<<<
 *     a = np.fromiter(it, dtype='u4')
 *     dp_mean = np.mean(a)
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr {
  PyObject_HEAD
  struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *__pyx_outer_scope;
  PyObject *__pyx_v_col;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":1450
 * 
 * 
 * def stat_baseq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":414
 * 
 * 
 * def stat_coverage_ext_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysam/csamtools.pxd":536
 *     cdef int truncate
 * 
 * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */
struct __pyx_obj_5pysam_9csamtools_IteratorColumnAllRefs {
  struct __pyx_obj_5pysam_9csamtools_IteratorColumn __pyx_base;
};


/* "pysam/csamtools.pxd":420
 *     cdef bam1_t * _delegate
 * 
 * cdef class Samfile:             # <<<<<<<<<<<<<<
 *     cdef char * _filename
 *     # pointer to samfile
 */
struct __pyx_obj_5pysam_9csamtools_Samfile {
  PyObject_HEAD
  struct __pyx_vtabstruct_5pysam_9csamtools_Samfile *__pyx_vtab;
  char *_filename;
  samfile_t *samfile;
  bam_index_t *index;
  int isbam;
  int isstream;
  int isremote;
  bam1_t *b;
  char *mode;
  int64_t start_offset;
};


/* "pysamstats.pyx":256
 * 
 * 
 * def stat_coverage_ext(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":100
 * 
 * 
 * def stat_coverage(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":1904
 * 
 * 
 * def stat_baseq_ext_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysamstats.pyx":2029
 *     # first need to load the coverage data into an array, to calculate the median
 *     recs = stat_coverage_gc(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based)
 *     it = ((rec['reads_all'], rec['gc']) for rec in recs)             # <<<<<<<<<<<<<<
 *     a = np.fromiter(it, dtype=[('dp', 'u4'), ('gc', 'u1')]).view(np.recarray)
 *     dp_mean = np.mean(a.dp)
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr {
  PyObject_HEAD
  struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *__pyx_outer_scope;
  PyObject *__pyx_v_rec;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};


/* "pysam/csamtools.pxd":415
 *     cdef char * _fetch( self, char * reference, int start, int end, int * length )
 * 
 * cdef class AlignedRead:             # <<<<<<<<<<<<<<
 * 
 *     # object that this AlignedRead represents
 */
struct __pyx_obj_5pysam_9csamtools_AlignedRead {
  PyObject_HEAD
  bam1_t *_delegate;
};


/* "pysamstats.pyx":1694
 * 
 * 
 * def stat_baseq_ext(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                    chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */
struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext {
  PyObject_HEAD
  PyObject *__pyx_v_chrom;
  PyObject *__pyx_v_col;
  PyObject *__pyx_v_end;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile;
  PyObject *__pyx_v_kwargs;
  PyObject *__pyx_v_one_based;
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile;
  PyObject *__pyx_v_start;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};



/* "pysam/csamtools.pxd":504
 *     cdef int cnext(self)
 * 
 * cdef class IteratorColumn:             # <<<<<<<<<<<<<<
 * 
 *     # result of the last plbuf_push
 */

struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumn {
  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_IteratorColumn *);
  char *(*getSequence)(struct __pyx_obj_5pysam_9csamtools_IteratorColumn *);
  PyObject *(*setMask)(struct __pyx_obj_5pysam_9csamtools_IteratorColumn *, PyObject *);
  PyObject *(*setupIteratorData)(struct __pyx_obj_5pysam_9csamtools_IteratorColumn *, int, int, int, struct __pyx_opt_args_5pysam_9csamtools_14IteratorColumn_setupIteratorData *__pyx_optional_args);
  PyObject *(*reset)(struct __pyx_obj_5pysam_9csamtools_IteratorColumn *, PyObject *, PyObject *, PyObject *);
};
static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumn *__pyx_vtabptr_5pysam_9csamtools_IteratorColumn;


/* "pysam/csamtools.pxd":480
 *     cdef int cnext(self)
 * 
 * cdef class IteratorRowAll(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam1_t * b
 *     cdef samfile_t * fp
 */

struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowAll {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_IteratorRowAll *);
  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_IteratorRowAll *);
};
static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowAll *__pyx_vtabptr_5pysam_9csamtools_IteratorRowAll;


/* "pysam/csamtools.pxd":408
 * # Note: need to declare all C fields and methods here
 * #
 * cdef class Fastafile:             # <<<<<<<<<<<<<<
 *     cdef char * _filename
 *     # pointer to fastafile
 */

struct __pyx_vtabstruct_5pysam_9csamtools_Fastafile {
  char *(*_fetch)(struct __pyx_obj_5pysam_9csamtools_Fastafile *, char *, int, int, int *);
};
static struct __pyx_vtabstruct_5pysam_9csamtools_Fastafile *__pyx_vtabptr_5pysam_9csamtools_Fastafile;


/* "pysam/csamtools.pxd":467
 *     pass
 * 
 * cdef class IteratorRowRegion(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam_iter_t             iter # iterator state object
 *     cdef bam1_t *               b
 */

struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *);
  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion *);
};
static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion *__pyx_vtabptr_5pysam_9csamtools_IteratorRowRegion;


/* "pysam/csamtools.pxd":536
 *     cdef int truncate
 * 
 * cdef class IteratorColumnAllRefs(IteratorColumn):             # <<<<<<<<<<<<<<
 *     pass
 * 
 */

struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnAllRefs {
  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnAllRefs *__pyx_vtabptr_5pysam_9csamtools_IteratorColumnAllRefs;


/* "pysam/csamtools.pxd":492
 *     cdef IteratorRowRegion rowiter
 * 
 * cdef class IteratorRowSelection(IteratorRow):             # <<<<<<<<<<<<<<
 *     cdef bam1_t * b
 *     cdef int current_pos
 */

struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowSelection {
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection *);
  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection *);
};
static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowSelection *__pyx_vtabptr_5pysam_9csamtools_IteratorRowSelection;


/* "pysam/csamtools.pxd":531
 *     cdef reset( self, tid, start, end )
 * 
 * cdef class IteratorColumnRegion(IteratorColumn):             # <<<<<<<<<<<<<<
 *     cdef int start
 *     cdef int end
 */

struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnRegion {
  struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumn __pyx_base;
};
static struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnRegion *__pyx_vtabptr_5pysam_9csamtools_IteratorColumnRegion;


/* "pysam/csamtools.pxd":420
 *     cdef bam1_t * _delegate
 * 
 * cdef class Samfile:             # <<<<<<<<<<<<<<
 *     cdef char * _filename
 *     # pointer to samfile
 */

struct __pyx_vtabstruct_5pysam_9csamtools_Samfile {
  bam_header_t *(*_buildHeader)(struct __pyx_obj_5pysam_9csamtools_Samfile *, PyObject *);
  bam1_t *(*getCurrent)(struct __pyx_obj_5pysam_9csamtools_Samfile *);
  int (*cnext)(struct __pyx_obj_5pysam_9csamtools_Samfile *);
  int (*write)(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_AlignedRead *, int __pyx_skip_dispatch);
  char *(*_getrname)(struct __pyx_obj_5pysam_9csamtools_Samfile *, int);
};
static struct __pyx_vtabstruct_5pysam_9csamtools_Samfile *__pyx_vtabptr_5pysam_9csamtools_Samfile;
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); /*proto*/
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
          if (acquire_gil) { \
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); \
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
              PyGILState_Release(__pyx_gilstate_save); \
          } else { \
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__); \
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil) \
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext() \
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif /* CYTHON_REFNANNY */
#define __Pyx_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)

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

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

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

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

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

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

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

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

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

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

static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname);

#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)) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

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

static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

static CYTHON_INLINE PY_LONG_LONG __Pyx_mod_PY_LONG_LONG(PY_LONG_LONG, PY_LONG_LONG); /* proto */

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

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

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

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

static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

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

static CYTHON_INLINE void __Pyx_RaiseImportError(PyObject *name);

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

static CYTHON_INLINE uint64_t __Pyx_pow_uint64_t(uint64_t, uint64_t); /* proto */

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint64_t(uint64_t);

static int __Pyx_Print(PyObject*, PyObject *, int); /*proto*/
#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
static PyObject* __pyx_print = 0;
static PyObject* __pyx_print_kwargs = 0;
#endif

static int __Pyx_PrintOne(PyObject* stream, PyObject *o); /*proto*/

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint32_t(uint32_t);

static CYTHON_INLINE uint32_t __Pyx_PyInt_from_py_uint32_t(PyObject *);

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    #define __Pyx_CREAL(z) ((z).real())
    #define __Pyx_CIMAG(z) ((z).imag())
  #else
    #define __Pyx_CREAL(z) (__real__(z))
    #define __Pyx_CIMAG(z) (__imag__(z))
  #endif
#else
    #define __Pyx_CREAL(z) ((z).real)
    #define __Pyx_CIMAG(z) ((z).imag)
#endif
#if defined(_WIN32) && defined(__cplusplus) && CYTHON_CCOMPLEX
    #define __Pyx_SET_CREAL(z,x) ((z).real(x))
    #define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
#else
    #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
    #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
#endif

static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float);

#if CYTHON_CCOMPLEX
    #define __Pyx_c_eqf(a, b)   ((a)==(b))
    #define __Pyx_c_sumf(a, b)  ((a)+(b))
    #define __Pyx_c_difff(a, b) ((a)-(b))
    #define __Pyx_c_prodf(a, b) ((a)*(b))
    #define __Pyx_c_quotf(a, b) ((a)/(b))
    #define __Pyx_c_negf(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zerof(z) ((z)==(float)0)
    #define __Pyx_c_conjf(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_absf(z)     (::std::abs(z))
        #define __Pyx_c_powf(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zerof(z) ((z)==0)
    #define __Pyx_c_conjf(z)    (conjf(z))
    #if 1
        #define __Pyx_c_absf(z)     (cabsf(z))
        #define __Pyx_c_powf(a, b)  (cpowf(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex);
    static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex);
    #if 1
        static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex);
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_complex, __pyx_t_float_complex);
    #endif
#endif

static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double);

#if CYTHON_CCOMPLEX
    #define __Pyx_c_eq(a, b)   ((a)==(b))
    #define __Pyx_c_sum(a, b)  ((a)+(b))
    #define __Pyx_c_diff(a, b) ((a)-(b))
    #define __Pyx_c_prod(a, b) ((a)*(b))
    #define __Pyx_c_quot(a, b) ((a)/(b))
    #define __Pyx_c_neg(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zero(z) ((z)==(double)0)
    #define __Pyx_c_conj(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_abs(z)     (::std::abs(z))
        #define __Pyx_c_pow(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zero(z) ((z)==0)
    #define __Pyx_c_conj(z)    (conj(z))
    #if 1
        #define __Pyx_c_abs(z)     (cabs(z))
        #define __Pyx_c_pow(a, b)  (cpow(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex);
    static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex);
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex);
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex, __pyx_t_double_complex);
    #endif
#endif

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject *);

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject *);

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject *);

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject *);

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject *);

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject *);

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject *);

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject *);

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject *);

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject *);

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject *);

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject *);

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject *);

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject *);

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject *);

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

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

static int __Pyx_check_binary_version(void);

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

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

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

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

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

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

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


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

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

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

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

/* Module declarations from '__builtin__' */

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

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

/* Module declarations from 'numpy' */

/* Module declarations from 'numpy' */
static PyTypeObject *__pyx_ptype_5numpy_dtype = 0;
static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0;
static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0;
static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0;
static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0;
static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/

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

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

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

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

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

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

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

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

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

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

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

/* Module declarations from '__builtin__' */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* Module declarations from 'cpython' */

/* Module declarations from 'pysam.csamtools' */
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_Fastafile = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_AlignedRead = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_Samfile = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_PileupProxy = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_PileupRead = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_IteratorRow = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_IteratorRowRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_IteratorRowAll = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_IteratorRowAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_IteratorRowSelection = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_IteratorColumn = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_IteratorColumnRegion = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_IteratorColumnAllRefs = 0;
static PyTypeObject *__pyx_ptype_5pysam_9csamtools_IndexedReads = 0;

/* Module declarations from 'pysamstats' */
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct__stat_coverage = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_1_stat_coverage_strand = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_2_stat_coverage_ext = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_4_stat_variation = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_5_stat_variation_strand = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_6_stat_tlen = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_7_stat_tlen_strand = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_8_stat_mapq = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_9_stat_mapq_strand = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_10_stat_baseq = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_11_stat_baseq_strand = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_12_stat_baseq_ext = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_14_stat_coverage_normed = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_15_genexpr = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_16_stat_coverage_gc = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc = 0;
static PyTypeObject *__pyx_ptype_10pysamstats___pyx_scope_struct_18_genexpr = 0;
static char *__pyx_v_10pysamstats_bam_nt16_rev_table;
static PyObject *__pyx_f_10pysamstats_construct_rec_coverage(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_coverage *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_coverage_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_coverage_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_coverage_ext(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_coverage_ext_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_variation(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_Fastafile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_variation *__pyx_optional_args); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_10pysamstats_init_pp_strand(struct __pyx_t_10pysamstats_CountPpStrand *); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_10pysamstats_incr_pp_strand(struct __pyx_t_10pysamstats_CountPpStrand *, int, int); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_variation_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_Fastafile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_variation_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_tlen(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_tlen *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_tlen_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_tlen_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_mapq(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_mapq *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_mapq_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_mapq_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_baseq(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_baseq *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_baseq_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_baseq_strand *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_baseq_ext(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_Fastafile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_baseq_ext_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *, struct __pyx_obj_5pysam_9csamtools_Fastafile *, struct __pyx_obj_5pysam_9csamtools_PileupProxy *, int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext_strand *__pyx_optional_args); /*proto*/
static CYTHON_INLINE int __pyx_f_10pysamstats_is_softclipped(bam1_t *); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_10pysamstats_get_seq_base(bam1_t *, uint32_t); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_10pysamstats_rootmean(uint64_t, unsigned int); /*proto*/
#define __Pyx_MODULE_NAME "pysamstats"
int __pyx_module_is_main_pysamstats = 0;

/* Implementation of 'pysamstats' */
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_round;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_RuntimeError;
static PyObject *__pyx_pf_10pysamstats_construct_rec_coverage(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_2stat_coverage(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_5write_coverage(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_7construct_rec_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_9stat_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_12write_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_14construct_rec_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_16stat_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_19write_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_21construct_rec_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_23stat_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_26write_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_28construct_rec_variation(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_30stat_variation(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_33write_variation(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_35construct_rec_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_37stat_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_40write_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_42construct_rec_tlen(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_44stat_tlen(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_47write_tlen(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_49construct_rec_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_51stat_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_54write_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_56construct_rec_mapq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_58stat_mapq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_61write_mapq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_63construct_rec_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_65stat_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_68write_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_70construct_rec_baseq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_72stat_baseq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_75write_baseq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_77construct_rec_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_79stat_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_82write_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_84construct_rec_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_86stat_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_89write_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_91construct_rec_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_93stat_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_96write_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_20stat_coverage_normed_genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_10pysamstats_98stat_coverage_normed(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_101write_coverage_normed(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_103stat_coverage_gc(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_gc_window_length, PyObject *__pyx_v_gc_window_offset, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_106write_coverage_gc(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_23stat_coverage_normed_gc_genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_pf_10pysamstats_108stat_coverage_normed_gc(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_111write_coverage_normed_gc(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_10pysamstats_113normalise_coords(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based); /* proto */
static PyObject *__pyx_pf_10pysamstats_115write_stats(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_statfun, PyObject *__pyx_v_fieldnames, PyObject *__pyx_v_outfile, PyObject *__pyx_v_samfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_dialect, PyObject *__pyx_v_write_header, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_progress, PyObject *__pyx_v_kwargs); /* proto */
static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
static char __pyx_k_5[] = "stat_coverage_strand";
static char __pyx_k_6[] = "reads_mate_other_chr";
static char __pyx_k_7[] = "reads_mate_same_strand";
static char __pyx_k_10[] = "reads_mate_unmapped_fwd";
static char __pyx_k_11[] = "reads_mate_unmapped_rev";
static char __pyx_k_12[] = "reads_mate_other_chr_fwd";
static char __pyx_k_13[] = "reads_mate_other_chr_rev";
static char __pyx_k_14[] = "reads_mate_same_strand_fwd";
static char __pyx_k_15[] = "reads_mate_same_strand_rev";
static char __pyx_k_16[] = "reads_softclipped_fwd";
static char __pyx_k_17[] = "reads_softclipped_rev";
static char __pyx_k_20[] = "stat_coverage_ext_strand";
static char __pyx_k_25[] = "stat_variation_strand";
static char __pyx_k_38[] = "rms_baseq_matches_pp";
static char __pyx_k_39[] = "rms_baseq_mismatches";
static char __pyx_k_40[] = "rms_baseq_mismatches_pp";
static char __pyx_k_43[] = "rms_baseq_matches_fwd";
static char __pyx_k_44[] = "rms_baseq_matches_rev";
static char __pyx_k_45[] = "rms_baseq_matches_pp_fwd";
static char __pyx_k_46[] = "rms_baseq_matches_pp_rev";
static char __pyx_k_47[] = "rms_baseq_mismatches_fwd";
static char __pyx_k_48[] = "rms_baseq_mismatches_rev";
static char __pyx_k_49[] = "rms_baseq_mismatches_pp_fwd";
static char __pyx_k_50[] = "rms_baseq_mismatches_pp_rev";
static char __pyx_k_53[] = "stat_baseq_ext_strand";
static char __pyx_k_56[] = "stat_coverage_normed";
static char __pyx_k_64[] = "stat_coverage_normed_gc";
static char __pyx_k_68[] = "%s rows in %.2fs (%d rows/s); batch in %.2fs (%d rows/s)";
static char __pyx_k_69[] = "%s rows in %.2fs (%d rows/s)";
static char __pyx_k_70[] = "ndarray is not C contiguous";
static char __pyx_k_72[] = "ndarray is not Fortran contiguous";
static char __pyx_k_74[] = "Non-native byte order not supported";
static char __pyx_k_76[] = "unknown dtype code in numpy.pxd (%d)";
static char __pyx_k_77[] = "Format string allocated too short, see comment in numpy.pxd";
static char __pyx_k_80[] = "Format string allocated too short.";
static char __pyx_k_82[] = "0.4.5";
static char __pyx_k_83[] = "=ACMGRSVTWYHKDBN";
static char __pyx_k_86[] = "/home/aliman/src/github/alimanfoo/pysamstats/pysamstats.pyx";
static char __pyx_k_93[] = "write_coverage_strand";
static char __pyx_k__A[] = "A";
static char __pyx_k__B[] = "B";
static char __pyx_k__C[] = "C";
static char __pyx_k__G[] = "G";
static char __pyx_k__H[] = "H";
static char __pyx_k__I[] = "I";
static char __pyx_k__L[] = "L";
static char __pyx_k__N[] = "N";
static char __pyx_k__O[] = "O";
static char __pyx_k__Q[] = "Q";
static char __pyx_k__T[] = "T";
static char __pyx_k__a[] = "a";
static char __pyx_k__b[] = "b";
static char __pyx_k__d[] = "d";
static char __pyx_k__f[] = "f";
static char __pyx_k__g[] = "g";
static char __pyx_k__h[] = "h";
static char __pyx_k__i[] = "i";
static char __pyx_k__l[] = "l";
static char __pyx_k__n[] = "n";
static char __pyx_k__q[] = "q";
static char __pyx_k_102[] = "write_coverage_ext_strand";
static char __pyx_k_111[] = "write_variation_strand";
static char __pyx_k_144[] = "write_baseq_ext_strand";
static char __pyx_k_149[] = "write_coverage_normed";
static char __pyx_k_154[] = "dp_normed_median_bygc";
static char __pyx_k_159[] = "write_coverage_normed_gc";
static char __pyx_k__NA[] = "NA";
static char __pyx_k__Zd[] = "Zd";
static char __pyx_k__Zf[] = "Zf";
static char __pyx_k__Zg[] = "Zg";
static char __pyx_k__dp[] = "dp";
static char __pyx_k__gc[] = "gc";
static char __pyx_k__it[] = "it";
static char __pyx_k__np[] = "np";
static char __pyx_k__u1[] = "u1";
static char __pyx_k__u4[] = "u4";
static char __pyx_k__col[] = "col";
static char __pyx_k__csv[] = "csv";
static char __pyx_k__end[] = "end";
static char __pyx_k__flt[] = "flt";
static char __pyx_k__pos[] = "pos";
static char __pyx_k__rec[] = "rec";
static char __pyx_k__ref[] = "ref";
static char __pyx_k__seq[] = "seq";
static char __pyx_k__sys[] = "sys";
static char __pyx_k__tid[] = "tid";
static char __pyx_k__A_pp[] = "A_pp";
static char __pyx_k__C_pp[] = "C_pp";
static char __pyx_k__G_pp[] = "G_pp";
static char __pyx_k__N_pp[] = "N_pp";
static char __pyx_k__T_pp[] = "T_pp";
static char __pyx_k__args[] = "args";
static char __pyx_k__mean[] = "mean";
static char __pyx_k__recs[] = "recs";
static char __pyx_k__time[] = "time";
static char __pyx_k__view[] = "view";
static char __pyx_k__A_fwd[] = "A_fwd";
static char __pyx_k__A_rev[] = "A_rev";
static char __pyx_k__C_fwd[] = "C_fwd";
static char __pyx_k__C_rev[] = "C_rev";
static char __pyx_k__G_fwd[] = "G_fwd";
static char __pyx_k__G_rev[] = "G_rev";
static char __pyx_k__N_fwd[] = "N_fwd";
static char __pyx_k__N_rev[] = "N_rev";
static char __pyx_k__T_fwd[] = "T_fwd";
static char __pyx_k__T_rev[] = "T_rev";
static char __pyx_k__after[] = "after";
static char __pyx_k__chrom[] = "chrom";
static char __pyx_k__dtype[] = "dtype";
static char __pyx_k__fetch[] = "fetch";
static char __pyx_k__numpy[] = "numpy";
static char __pyx_k__range[] = "range";
static char __pyx_k__round[] = "round";
static char __pyx_k__start[] = "start";
static char __pyx_k__upper[] = "upper";
static char __pyx_k__before[] = "before";
static char __pyx_k__bisect[] = "bisect";
static char __pyx_k__fafile[] = "fafile";
static char __pyx_k__kwargs[] = "kwargs";
static char __pyx_k__median[] = "median";
static char __pyx_k__pileup[] = "pileup";
static char __pyx_k__stderr[] = "stderr";
static char __pyx_k__writer[] = "writer";
static char __pyx_k__Counter[] = "Counter";
static char __pyx_k__counter[] = "counter";
static char __pyx_k__dialect[] = "dialect";
static char __pyx_k__dp_mean[] = "dp_mean";
static char __pyx_k__elapsed[] = "elapsed";
static char __pyx_k__genexpr[] = "genexpr";
static char __pyx_k__matches[] = "matches";
static char __pyx_k__modulus[] = "modulus";
static char __pyx_k__outfile[] = "outfile";
static char __pyx_k__samfile[] = "samfile";
static char __pyx_k__statfun[] = "statfun";
static char __pyx_k__A_pp_fwd[] = "A_pp_fwd";
static char __pyx_k__A_pp_rev[] = "A_pp_rev";
static char __pyx_k__C_pp_fwd[] = "C_pp_fwd";
static char __pyx_k__C_pp_rev[] = "C_pp_rev";
static char __pyx_k__G_pp_fwd[] = "G_pp_fwd";
static char __pyx_k__G_pp_rev[] = "G_pp_rev";
static char __pyx_k__N_pp_fwd[] = "N_pp_fwd";
static char __pyx_k__N_pp_rev[] = "N_pp_rev";
static char __pyx_k__T_pp_fwd[] = "T_pp_fwd";
static char __pyx_k__T_pp_rev[] = "T_pp_rev";
static char __pyx_k____main__[] = "__main__";
static char __pyx_k____test__[] = "__test__";
static char __pyx_k__fromiter[] = "fromiter";
static char __pyx_k__gc_count[] = "gc_count";
static char __pyx_k__getrname[] = "getrname";
static char __pyx_k__max_mapq[] = "max_mapq";
static char __pyx_k__progress[] = "progress";
static char __pyx_k__reads_pp[] = "reads_pp";
static char __pyx_k__recarray[] = "recarray";
static char __pyx_k__rms_mapq[] = "rms_mapq";
static char __pyx_k__rms_tlen[] = "rms_tlen";
static char __pyx_k__std_tlen[] = "std_tlen";
static char __pyx_k__writerow[] = "writerow";
static char __pyx_k__after_all[] = "after_all";
static char __pyx_k__deletions[] = "deletions";
static char __pyx_k__dp_median[] = "dp_median";
static char __pyx_k__excel_tab[] = "excel_tab";
static char __pyx_k__mean_tlen[] = "mean_tlen";
static char __pyx_k__one_based[] = "one_based";
static char __pyx_k__reads_all[] = "reads_all";
static char __pyx_k__reads_fwd[] = "reads_fwd";
static char __pyx_k__reads_rev[] = "reads_rev";
static char __pyx_k__reference[] = "reference";
static char __pyx_k__rms_baseq[] = "rms_baseq";
static char __pyx_k__stat_mapq[] = "stat_mapq";
static char __pyx_k__stat_tlen[] = "stat_tlen";
static char __pyx_k__writerows[] = "writerows";
static char __pyx_k__DictWriter[] = "DictWriter";
static char __pyx_k__ValueError[] = "ValueError";
static char __pyx_k__before_all[] = "before_all";
static char __pyx_k__fieldnames[] = "fieldnames";
static char __pyx_k__gc_percent[] = "gc_percent";
static char __pyx_k__insertions[] = "insertions";
static char __pyx_k__matches_pp[] = "matches_pp";
static char __pyx_k__mismatches[] = "mismatches";
static char __pyx_k__percentile[] = "percentile";
static char __pyx_k__pysamstats[] = "pysamstats";
static char __pyx_k__ref_window[] = "ref_window";
static char __pyx_k__stat_baseq[] = "stat_baseq";
static char __pyx_k__write_mapq[] = "write_mapq";
static char __pyx_k__write_tlen[] = "write_tlen";
static char __pyx_k____version__[] = "__version__";
static char __pyx_k__bisect_left[] = "bisect_left";
static char __pyx_k__collections[] = "collections";
static char __pyx_k__elapsed_all[] = "elapsed_all";
static char __pyx_k__matches_fwd[] = "matches_fwd";
static char __pyx_k__matches_rev[] = "matches_rev";
static char __pyx_k__max_mapq_pp[] = "max_mapq_pp";
static char __pyx_k__reads_mapq0[] = "reads_mapq0";
static char __pyx_k__rms_mapq_pp[] = "rms_mapq_pp";
static char __pyx_k__rms_tlen_pp[] = "rms_tlen_pp";
static char __pyx_k__std_tlen_pp[] = "std_tlen_pp";
static char __pyx_k__write_baseq[] = "write_baseq";
static char __pyx_k__write_stats[] = "write_stats";
static char __pyx_k__writeheader[] = "writeheader";
static char __pyx_k__RuntimeError[] = "RuntimeError";
static char __pyx_k__deletions_pp[] = "deletions_pp";
static char __pyx_k__dp_mean_bygc[] = "dp_mean_bygc";
static char __pyx_k__max_mapq_fwd[] = "max_mapq_fwd";
static char __pyx_k__max_mapq_rev[] = "max_mapq_rev";
static char __pyx_k__mean_tlen_pp[] = "mean_tlen_pp";
static char __pyx_k__reads_pp_fwd[] = "reads_pp_fwd";
static char __pyx_k__reads_pp_rev[] = "reads_pp_rev";
static char __pyx_k__rms_baseq_pp[] = "rms_baseq_pp";
static char __pyx_k__rms_mapq_fwd[] = "rms_mapq_fwd";
static char __pyx_k__rms_mapq_rev[] = "rms_mapq_rev";
static char __pyx_k__rms_tlen_fwd[] = "rms_tlen_fwd";
static char __pyx_k__rms_tlen_rev[] = "rms_tlen_rev";
static char __pyx_k__std_tlen_fwd[] = "std_tlen_fwd";
static char __pyx_k__std_tlen_rev[] = "std_tlen_rev";
static char __pyx_k__write_header[] = "write_header";
static char __pyx_k__batch_elapsed[] = "batch_elapsed";
static char __pyx_k__count_nonzero[] = "count_nonzero";
static char __pyx_k__deletions_fwd[] = "deletions_fwd";
static char __pyx_k__deletions_rev[] = "deletions_rev";
static char __pyx_k__dp_percentile[] = "dp_percentile";
static char __pyx_k__insertions_pp[] = "insertions_pp";
static char __pyx_k__mean_tlen_fwd[] = "mean_tlen_fwd";
static char __pyx_k__mean_tlen_rev[] = "mean_tlen_rev";
static char __pyx_k__mismatches_pp[] = "mismatches_pp";
static char __pyx_k__rms_baseq_fwd[] = "rms_baseq_fwd";
static char __pyx_k__rms_baseq_rev[] = "rms_baseq_rev";
static char __pyx_k__stat_coverage[] = "stat_coverage";
static char __pyx_k__dp_median_bygc[] = "dp_median_bygc";
static char __pyx_k__dp_normed_mean[] = "dp_normed_mean";
static char __pyx_k__dp_percentiles[] = "dp_percentiles";
static char __pyx_k__insertions_fwd[] = "insertions_fwd";
static char __pyx_k__insertions_rev[] = "insertions_rev";
static char __pyx_k__matches_pp_fwd[] = "matches_pp_fwd";
static char __pyx_k__matches_pp_rev[] = "matches_pp_rev";
static char __pyx_k__mismatches_fwd[] = "mismatches_fwd";
static char __pyx_k__mismatches_rev[] = "mismatches_rev";
static char __pyx_k__reads_faceaway[] = "reads_faceaway";
static char __pyx_k__reads_mapq0_pp[] = "reads_mapq0_pp";
static char __pyx_k__ref_window_end[] = "ref_window_end";
static char __pyx_k__stat_baseq_ext[] = "stat_baseq_ext";
static char __pyx_k__stat_variation[] = "stat_variation";
static char __pyx_k__write_coverage[] = "write_coverage";
static char __pyx_k__max_mapq_pp_fwd[] = "max_mapq_pp_fwd";
static char __pyx_k__max_mapq_pp_rev[] = "max_mapq_pp_rev";
static char __pyx_k__reads_duplicate[] = "reads_duplicate";
static char __pyx_k__reads_mapq0_fwd[] = "reads_mapq0_fwd";
static char __pyx_k__reads_mapq0_rev[] = "reads_mapq0_rev";
static char __pyx_k__rms_mapq_pp_fwd[] = "rms_mapq_pp_fwd";
static char __pyx_k__rms_mapq_pp_rev[] = "rms_mapq_pp_rev";
static char __pyx_k__rms_tlen_pp_fwd[] = "rms_tlen_pp_fwd";
static char __pyx_k__rms_tlen_pp_rev[] = "rms_tlen_pp_rev";
static char __pyx_k__std_tlen_pp_fwd[] = "std_tlen_pp_fwd";
static char __pyx_k__std_tlen_pp_rev[] = "std_tlen_pp_rev";
static char __pyx_k__write_baseq_ext[] = "write_baseq_ext";
static char __pyx_k__write_variation[] = "write_variation";
static char __pyx_k__deletions_pp_fwd[] = "deletions_pp_fwd";
static char __pyx_k__deletions_pp_rev[] = "deletions_pp_rev";
static char __pyx_k__dp_normed_median[] = "dp_normed_median";
static char __pyx_k__dp_percentile_gc[] = "dp_percentile_gc";
static char __pyx_k__gc_window_length[] = "gc_window_length";
static char __pyx_k__gc_window_offset[] = "gc_window_offset";
static char __pyx_k__mean_tlen_pp_fwd[] = "mean_tlen_pp_fwd";
static char __pyx_k__mean_tlen_pp_rev[] = "mean_tlen_pp_rev";
static char __pyx_k__normalise_coords[] = "normalise_coords";
static char __pyx_k__ref_window_start[] = "ref_window_start";
static char __pyx_k__rms_baseq_pp_fwd[] = "rms_baseq_pp_fwd";
static char __pyx_k__rms_baseq_pp_rev[] = "rms_baseq_pp_rev";
static char __pyx_k__stat_coverage_gc[] = "stat_coverage_gc";
static char __pyx_k__stat_mapq_strand[] = "stat_mapq_strand";
static char __pyx_k__stat_tlen_strand[] = "stat_tlen_strand";
static char __pyx_k__dp_normed_mean_gc[] = "dp_normed_mean_gc";
static char __pyx_k__insertions_pp_fwd[] = "insertions_pp_fwd";
static char __pyx_k__insertions_pp_rev[] = "insertions_pp_rev";
static char __pyx_k__mismatches_pp_fwd[] = "mismatches_pp_fwd";
static char __pyx_k__mismatches_pp_rev[] = "mismatches_pp_rev";
static char __pyx_k__reads_softclipped[] = "reads_softclipped";
static char __pyx_k__rms_baseq_matches[] = "rms_baseq_matches";
static char __pyx_k__stat_baseq_strand[] = "stat_baseq_strand";
static char __pyx_k__stat_coverage_ext[] = "stat_coverage_ext";
static char __pyx_k__write_coverage_gc[] = "write_coverage_gc";
static char __pyx_k__write_mapq_strand[] = "write_mapq_strand";
static char __pyx_k__write_tlen_strand[] = "write_tlen_strand";
static char __pyx_k__dp_percentile_bygc[] = "dp_percentile_bygc";
static char __pyx_k__reads_faceaway_fwd[] = "reads_faceaway_fwd";
static char __pyx_k__reads_faceaway_rev[] = "reads_faceaway_rev";
static char __pyx_k__reads_mapq0_pp_fwd[] = "reads_mapq0_pp_fwd";
static char __pyx_k__reads_mapq0_pp_rev[] = "reads_mapq0_pp_rev";
static char __pyx_k__write_baseq_strand[] = "write_baseq_strand";
static char __pyx_k__write_coverage_ext[] = "write_coverage_ext";
static char __pyx_k__dp_normed_mean_bygc[] = "dp_normed_mean_bygc";
static char __pyx_k__dp_normed_median_gc[] = "dp_normed_median_gc";
static char __pyx_k__dp_percentiles_bygc[] = "dp_percentiles_bygc";
static char __pyx_k__reads_duplicate_fwd[] = "reads_duplicate_fwd";
static char __pyx_k__reads_duplicate_rev[] = "reads_duplicate_rev";
static char __pyx_k__reads_mate_unmapped[] = "reads_mate_unmapped";
static PyObject *__pyx_n_s_10;
static PyObject *__pyx_n_s_102;
static PyObject *__pyx_n_s_11;
static PyObject *__pyx_n_s_111;
static PyObject *__pyx_n_s_12;
static PyObject *__pyx_n_s_13;
static PyObject *__pyx_n_s_14;
static PyObject *__pyx_n_s_144;
static PyObject *__pyx_n_s_149;
static PyObject *__pyx_n_s_15;
static PyObject *__pyx_n_s_154;
static PyObject *__pyx_n_s_159;
static PyObject *__pyx_n_s_16;
static PyObject *__pyx_n_s_17;
static PyObject *__pyx_n_s_20;
static PyObject *__pyx_n_s_25;
static PyObject *__pyx_n_s_38;
static PyObject *__pyx_n_s_39;
static PyObject *__pyx_n_s_40;
static PyObject *__pyx_n_s_43;
static PyObject *__pyx_n_s_44;
static PyObject *__pyx_n_s_45;
static PyObject *__pyx_n_s_46;
static PyObject *__pyx_n_s_47;
static PyObject *__pyx_n_s_48;
static PyObject *__pyx_n_s_49;
static PyObject *__pyx_n_s_5;
static PyObject *__pyx_n_s_50;
static PyObject *__pyx_n_s_53;
static PyObject *__pyx_n_s_56;
static PyObject *__pyx_n_s_6;
static PyObject *__pyx_n_s_64;
static PyObject *__pyx_kp_s_68;
static PyObject *__pyx_kp_s_69;
static PyObject *__pyx_n_s_7;
static PyObject *__pyx_kp_u_70;
static PyObject *__pyx_kp_u_72;
static PyObject *__pyx_kp_u_74;
static PyObject *__pyx_kp_u_76;
static PyObject *__pyx_kp_u_77;
static PyObject *__pyx_kp_u_80;
static PyObject *__pyx_kp_s_82;
static PyObject *__pyx_kp_s_86;
static PyObject *__pyx_n_s_93;
static PyObject *__pyx_n_s__A;
static PyObject *__pyx_n_s__A_fwd;
static PyObject *__pyx_n_s__A_pp;
static PyObject *__pyx_n_s__A_pp_fwd;
static PyObject *__pyx_n_s__A_pp_rev;
static PyObject *__pyx_n_s__A_rev;
static PyObject *__pyx_n_s__C;
static PyObject *__pyx_n_s__C_fwd;
static PyObject *__pyx_n_s__C_pp;
static PyObject *__pyx_n_s__C_pp_fwd;
static PyObject *__pyx_n_s__C_pp_rev;
static PyObject *__pyx_n_s__C_rev;
static PyObject *__pyx_n_s__Counter;
static PyObject *__pyx_n_s__DictWriter;
static PyObject *__pyx_n_s__G;
static PyObject *__pyx_n_s__G_fwd;
static PyObject *__pyx_n_s__G_pp;
static PyObject *__pyx_n_s__G_pp_fwd;
static PyObject *__pyx_n_s__G_pp_rev;
static PyObject *__pyx_n_s__G_rev;
static PyObject *__pyx_n_s__N;
static PyObject *__pyx_n_s__NA;
static PyObject *__pyx_n_s__N_fwd;
static PyObject *__pyx_n_s__N_pp;
static PyObject *__pyx_n_s__N_pp_fwd;
static PyObject *__pyx_n_s__N_pp_rev;
static PyObject *__pyx_n_s__N_rev;
static PyObject *__pyx_n_s__RuntimeError;
static PyObject *__pyx_n_s__T;
static PyObject *__pyx_n_s__T_fwd;
static PyObject *__pyx_n_s__T_pp;
static PyObject *__pyx_n_s__T_pp_fwd;
static PyObject *__pyx_n_s__T_pp_rev;
static PyObject *__pyx_n_s__T_rev;
static PyObject *__pyx_n_s__ValueError;
static PyObject *__pyx_n_s____main__;
static PyObject *__pyx_n_s____test__;
static PyObject *__pyx_n_s____version__;
static PyObject *__pyx_n_s__a;
static PyObject *__pyx_n_s__after;
static PyObject *__pyx_n_s__after_all;
static PyObject *__pyx_n_s__args;
static PyObject *__pyx_n_s__b;
static PyObject *__pyx_n_s__batch_elapsed;
static PyObject *__pyx_n_s__before;
static PyObject *__pyx_n_s__before_all;
static PyObject *__pyx_n_s__bisect;
static PyObject *__pyx_n_s__bisect_left;
static PyObject *__pyx_n_s__chrom;
static PyObject *__pyx_n_s__col;
static PyObject *__pyx_n_s__collections;
static PyObject *__pyx_n_s__count_nonzero;
static PyObject *__pyx_n_s__counter;
static PyObject *__pyx_n_s__csv;
static PyObject *__pyx_n_s__deletions;
static PyObject *__pyx_n_s__deletions_fwd;
static PyObject *__pyx_n_s__deletions_pp;
static PyObject *__pyx_n_s__deletions_pp_fwd;
static PyObject *__pyx_n_s__deletions_pp_rev;
static PyObject *__pyx_n_s__deletions_rev;
static PyObject *__pyx_n_s__dialect;
static PyObject *__pyx_n_s__dp;
static PyObject *__pyx_n_s__dp_mean;
static PyObject *__pyx_n_s__dp_mean_bygc;
static PyObject *__pyx_n_s__dp_median;
static PyObject *__pyx_n_s__dp_median_bygc;
static PyObject *__pyx_n_s__dp_normed_mean;
static PyObject *__pyx_n_s__dp_normed_mean_bygc;
static PyObject *__pyx_n_s__dp_normed_mean_gc;
static PyObject *__pyx_n_s__dp_normed_median;
static PyObject *__pyx_n_s__dp_normed_median_gc;
static PyObject *__pyx_n_s__dp_percentile;
static PyObject *__pyx_n_s__dp_percentile_bygc;
static PyObject *__pyx_n_s__dp_percentile_gc;
static PyObject *__pyx_n_s__dp_percentiles;
static PyObject *__pyx_n_s__dp_percentiles_bygc;
static PyObject *__pyx_n_s__dtype;
static PyObject *__pyx_n_s__elapsed;
static PyObject *__pyx_n_s__elapsed_all;
static PyObject *__pyx_n_s__end;
static PyObject *__pyx_n_s__excel_tab;
static PyObject *__pyx_n_s__fafile;
static PyObject *__pyx_n_s__fetch;
static PyObject *__pyx_n_s__fieldnames;
static PyObject *__pyx_n_s__flt;
static PyObject *__pyx_n_s__fromiter;
static PyObject *__pyx_n_s__gc;
static PyObject *__pyx_n_s__gc_count;
static PyObject *__pyx_n_s__gc_percent;
static PyObject *__pyx_n_s__gc_window_length;
static PyObject *__pyx_n_s__gc_window_offset;
static PyObject *__pyx_n_s__genexpr;
static PyObject *__pyx_n_s__getrname;
static PyObject *__pyx_n_s__i;
static PyObject *__pyx_n_s__insertions;
static PyObject *__pyx_n_s__insertions_fwd;
static PyObject *__pyx_n_s__insertions_pp;
static PyObject *__pyx_n_s__insertions_pp_fwd;
static PyObject *__pyx_n_s__insertions_pp_rev;
static PyObject *__pyx_n_s__insertions_rev;
static PyObject *__pyx_n_s__it;
static PyObject *__pyx_n_s__kwargs;
static PyObject *__pyx_n_s__matches;
static PyObject *__pyx_n_s__matches_fwd;
static PyObject *__pyx_n_s__matches_pp;
static PyObject *__pyx_n_s__matches_pp_fwd;
static PyObject *__pyx_n_s__matches_pp_rev;
static PyObject *__pyx_n_s__matches_rev;
static PyObject *__pyx_n_s__max_mapq;
static PyObject *__pyx_n_s__max_mapq_fwd;
static PyObject *__pyx_n_s__max_mapq_pp;
static PyObject *__pyx_n_s__max_mapq_pp_fwd;
static PyObject *__pyx_n_s__max_mapq_pp_rev;
static PyObject *__pyx_n_s__max_mapq_rev;
static PyObject *__pyx_n_s__mean;
static PyObject *__pyx_n_s__mean_tlen;
static PyObject *__pyx_n_s__mean_tlen_fwd;
static PyObject *__pyx_n_s__mean_tlen_pp;
static PyObject *__pyx_n_s__mean_tlen_pp_fwd;
static PyObject *__pyx_n_s__mean_tlen_pp_rev;
static PyObject *__pyx_n_s__mean_tlen_rev;
static PyObject *__pyx_n_s__median;
static PyObject *__pyx_n_s__mismatches;
static PyObject *__pyx_n_s__mismatches_fwd;
static PyObject *__pyx_n_s__mismatches_pp;
static PyObject *__pyx_n_s__mismatches_pp_fwd;
static PyObject *__pyx_n_s__mismatches_pp_rev;
static PyObject *__pyx_n_s__mismatches_rev;
static PyObject *__pyx_n_s__modulus;
static PyObject *__pyx_n_s__n;
static PyObject *__pyx_n_s__normalise_coords;
static PyObject *__pyx_n_s__np;
static PyObject *__pyx_n_s__numpy;
static PyObject *__pyx_n_s__one_based;
static PyObject *__pyx_n_s__outfile;
static PyObject *__pyx_n_s__percentile;
static PyObject *__pyx_n_s__pileup;
static PyObject *__pyx_n_s__pos;
static PyObject *__pyx_n_s__progress;
static PyObject *__pyx_n_s__pysamstats;
static PyObject *__pyx_n_s__q;
static PyObject *__pyx_n_s__range;
static PyObject *__pyx_n_s__reads_all;
static PyObject *__pyx_n_s__reads_duplicate;
static PyObject *__pyx_n_s__reads_duplicate_fwd;
static PyObject *__pyx_n_s__reads_duplicate_rev;
static PyObject *__pyx_n_s__reads_faceaway;
static PyObject *__pyx_n_s__reads_faceaway_fwd;
static PyObject *__pyx_n_s__reads_faceaway_rev;
static PyObject *__pyx_n_s__reads_fwd;
static PyObject *__pyx_n_s__reads_mapq0;
static PyObject *__pyx_n_s__reads_mapq0_fwd;
static PyObject *__pyx_n_s__reads_mapq0_pp;
static PyObject *__pyx_n_s__reads_mapq0_pp_fwd;
static PyObject *__pyx_n_s__reads_mapq0_pp_rev;
static PyObject *__pyx_n_s__reads_mapq0_rev;
static PyObject *__pyx_n_s__reads_mate_unmapped;
static PyObject *__pyx_n_s__reads_pp;
static PyObject *__pyx_n_s__reads_pp_fwd;
static PyObject *__pyx_n_s__reads_pp_rev;
static PyObject *__pyx_n_s__reads_rev;
static PyObject *__pyx_n_s__reads_softclipped;
static PyObject *__pyx_n_s__rec;
static PyObject *__pyx_n_s__recarray;
static PyObject *__pyx_n_s__recs;
static PyObject *__pyx_n_s__ref;
static PyObject *__pyx_n_s__ref_window;
static PyObject *__pyx_n_s__ref_window_end;
static PyObject *__pyx_n_s__ref_window_start;
static PyObject *__pyx_n_s__reference;
static PyObject *__pyx_n_s__rms_baseq;
static PyObject *__pyx_n_s__rms_baseq_fwd;
static PyObject *__pyx_n_s__rms_baseq_matches;
static PyObject *__pyx_n_s__rms_baseq_pp;
static PyObject *__pyx_n_s__rms_baseq_pp_fwd;
static PyObject *__pyx_n_s__rms_baseq_pp_rev;
static PyObject *__pyx_n_s__rms_baseq_rev;
static PyObject *__pyx_n_s__rms_mapq;
static PyObject *__pyx_n_s__rms_mapq_fwd;
static PyObject *__pyx_n_s__rms_mapq_pp;
static PyObject *__pyx_n_s__rms_mapq_pp_fwd;
static PyObject *__pyx_n_s__rms_mapq_pp_rev;
static PyObject *__pyx_n_s__rms_mapq_rev;
static PyObject *__pyx_n_s__rms_tlen;
static PyObject *__pyx_n_s__rms_tlen_fwd;
static PyObject *__pyx_n_s__rms_tlen_pp;
static PyObject *__pyx_n_s__rms_tlen_pp_fwd;
static PyObject *__pyx_n_s__rms_tlen_pp_rev;
static PyObject *__pyx_n_s__rms_tlen_rev;
static PyObject *__pyx_n_s__round;
static PyObject *__pyx_n_s__samfile;
static PyObject *__pyx_n_s__seq;
static PyObject *__pyx_n_s__start;
static PyObject *__pyx_n_s__stat_baseq;
static PyObject *__pyx_n_s__stat_baseq_ext;
static PyObject *__pyx_n_s__stat_baseq_strand;
static PyObject *__pyx_n_s__stat_coverage;
static PyObject *__pyx_n_s__stat_coverage_ext;
static PyObject *__pyx_n_s__stat_coverage_gc;
static PyObject *__pyx_n_s__stat_mapq;
static PyObject *__pyx_n_s__stat_mapq_strand;
static PyObject *__pyx_n_s__stat_tlen;
static PyObject *__pyx_n_s__stat_tlen_strand;
static PyObject *__pyx_n_s__stat_variation;
static PyObject *__pyx_n_s__statfun;
static PyObject *__pyx_n_s__std_tlen;
static PyObject *__pyx_n_s__std_tlen_fwd;
static PyObject *__pyx_n_s__std_tlen_pp;
static PyObject *__pyx_n_s__std_tlen_pp_fwd;
static PyObject *__pyx_n_s__std_tlen_pp_rev;
static PyObject *__pyx_n_s__std_tlen_rev;
static PyObject *__pyx_n_s__stderr;
static PyObject *__pyx_n_s__sys;
static PyObject *__pyx_n_s__tid;
static PyObject *__pyx_n_s__time;
static PyObject *__pyx_n_s__u1;
static PyObject *__pyx_n_s__u4;
static PyObject *__pyx_n_s__upper;
static PyObject *__pyx_n_s__view;
static PyObject *__pyx_n_s__write_baseq;
static PyObject *__pyx_n_s__write_baseq_ext;
static PyObject *__pyx_n_s__write_baseq_strand;
static PyObject *__pyx_n_s__write_coverage;
static PyObject *__pyx_n_s__write_coverage_ext;
static PyObject *__pyx_n_s__write_coverage_gc;
static PyObject *__pyx_n_s__write_header;
static PyObject *__pyx_n_s__write_mapq;
static PyObject *__pyx_n_s__write_mapq_strand;
static PyObject *__pyx_n_s__write_stats;
static PyObject *__pyx_n_s__write_tlen;
static PyObject *__pyx_n_s__write_tlen_strand;
static PyObject *__pyx_n_s__write_variation;
static PyObject *__pyx_n_s__writeheader;
static PyObject *__pyx_n_s__writer;
static PyObject *__pyx_n_s__writerow;
static PyObject *__pyx_n_s__writerows;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_15;
static PyObject *__pyx_int_101;
static PyObject *__pyx_int_150;
static PyObject *__pyx_int_300;
static PyObject *__pyx_k_1;
static PyObject *__pyx_k_3;
static PyObject *__pyx_k_8;
static PyObject *__pyx_k_18;
static PyObject *__pyx_k_21;
static PyObject *__pyx_k_23;
static PyObject *__pyx_k_26;
static PyObject *__pyx_k_28;
static PyObject *__pyx_k_30;
static PyObject *__pyx_k_32;
static PyObject *__pyx_k_34;
static PyObject *__pyx_k_36;
static PyObject *__pyx_k_41;
static PyObject *__pyx_k_51;
static PyObject *__pyx_k_54;
static PyObject *__pyx_k_57;
static PyObject *__pyx_k_59;
static PyObject *__pyx_k_65;
static PyObject *__pyx_k_66;
static PyObject *__pyx_k_67;
static PyObject *__pyx_k_tuple_2;
static PyObject *__pyx_k_tuple_4;
static PyObject *__pyx_k_tuple_9;
static PyObject *__pyx_k_tuple_19;
static PyObject *__pyx_k_tuple_22;
static PyObject *__pyx_k_tuple_24;
static PyObject *__pyx_k_tuple_27;
static PyObject *__pyx_k_tuple_29;
static PyObject *__pyx_k_tuple_31;
static PyObject *__pyx_k_tuple_33;
static PyObject *__pyx_k_tuple_35;
static PyObject *__pyx_k_tuple_37;
static PyObject *__pyx_k_tuple_42;
static PyObject *__pyx_k_tuple_52;
static PyObject *__pyx_k_tuple_55;
static PyObject *__pyx_k_tuple_58;
static PyObject *__pyx_k_tuple_60;
static PyObject *__pyx_k_tuple_61;
static PyObject *__pyx_k_tuple_62;
static PyObject *__pyx_k_tuple_63;
static PyObject *__pyx_k_tuple_71;
static PyObject *__pyx_k_tuple_73;
static PyObject *__pyx_k_tuple_75;
static PyObject *__pyx_k_tuple_78;
static PyObject *__pyx_k_tuple_79;
static PyObject *__pyx_k_tuple_81;
static PyObject *__pyx_k_tuple_84;
static PyObject *__pyx_k_tuple_87;
static PyObject *__pyx_k_tuple_89;
static PyObject *__pyx_k_tuple_91;
static PyObject *__pyx_k_tuple_94;
static PyObject *__pyx_k_tuple_96;
static PyObject *__pyx_k_tuple_98;
static PyObject *__pyx_k_tuple_100;
static PyObject *__pyx_k_tuple_103;
static PyObject *__pyx_k_tuple_105;
static PyObject *__pyx_k_tuple_107;
static PyObject *__pyx_k_tuple_109;
static PyObject *__pyx_k_tuple_112;
static PyObject *__pyx_k_tuple_114;
static PyObject *__pyx_k_tuple_116;
static PyObject *__pyx_k_tuple_118;
static PyObject *__pyx_k_tuple_120;
static PyObject *__pyx_k_tuple_122;
static PyObject *__pyx_k_tuple_124;
static PyObject *__pyx_k_tuple_126;
static PyObject *__pyx_k_tuple_128;
static PyObject *__pyx_k_tuple_130;
static PyObject *__pyx_k_tuple_132;
static PyObject *__pyx_k_tuple_134;
static PyObject *__pyx_k_tuple_136;
static PyObject *__pyx_k_tuple_138;
static PyObject *__pyx_k_tuple_140;
static PyObject *__pyx_k_tuple_142;
static PyObject *__pyx_k_tuple_145;
static PyObject *__pyx_k_tuple_147;
static PyObject *__pyx_k_tuple_150;
static PyObject *__pyx_k_tuple_152;
static PyObject *__pyx_k_tuple_155;
static PyObject *__pyx_k_tuple_157;
static PyObject *__pyx_k_tuple_160;
static PyObject *__pyx_k_tuple_162;
static PyObject *__pyx_k_codeobj_85;
static PyObject *__pyx_k_codeobj_88;
static PyObject *__pyx_k_codeobj_90;
static PyObject *__pyx_k_codeobj_92;
static PyObject *__pyx_k_codeobj_95;
static PyObject *__pyx_k_codeobj_97;
static PyObject *__pyx_k_codeobj_99;
static PyObject *__pyx_k_codeobj_101;
static PyObject *__pyx_k_codeobj_104;
static PyObject *__pyx_k_codeobj_106;
static PyObject *__pyx_k_codeobj_108;
static PyObject *__pyx_k_codeobj_110;
static PyObject *__pyx_k_codeobj_113;
static PyObject *__pyx_k_codeobj_115;
static PyObject *__pyx_k_codeobj_117;
static PyObject *__pyx_k_codeobj_119;
static PyObject *__pyx_k_codeobj_121;
static PyObject *__pyx_k_codeobj_123;
static PyObject *__pyx_k_codeobj_125;
static PyObject *__pyx_k_codeobj_127;
static PyObject *__pyx_k_codeobj_129;
static PyObject *__pyx_k_codeobj_131;
static PyObject *__pyx_k_codeobj_133;
static PyObject *__pyx_k_codeobj_135;
static PyObject *__pyx_k_codeobj_137;
static PyObject *__pyx_k_codeobj_139;
static PyObject *__pyx_k_codeobj_141;
static PyObject *__pyx_k_codeobj_143;
static PyObject *__pyx_k_codeobj_146;
static PyObject *__pyx_k_codeobj_148;
static PyObject *__pyx_k_codeobj_151;
static PyObject *__pyx_k_codeobj_153;
static PyObject *__pyx_k_codeobj_156;
static PyObject *__pyx_k_codeobj_158;
static PyObject *__pyx_k_codeobj_161;
static PyObject *__pyx_k_codeobj_163;

/* "pysamstats.pyx":65
 * 
 * 
 * cpdef object construct_rec_coverage(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */

static PyObject *__pyx_pw_10pysamstats_1construct_rec_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_coverage(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_coverage *__pyx_optional_args) {
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  unsigned int __pyx_v_reads_pp;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_coverage", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":75
 *     cdef uint32_t flag
 *     cdef bint is_proper_pair
 *     cdef unsigned int reads_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":78
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); 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_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":79
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":82
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":83
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":86
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":87
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":88
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":89
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":90
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         if is_proper_pair:
 *             reads_pp += 1
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":91
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 * 
 */
    if (__pyx_v_is_proper_pair) {

      /* "pysamstats.pyx":92
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:
 *             reads_pp += 1             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom,
 */
      __pyx_v_reads_pp = (__pyx_v_reads_pp + 1);
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  /* "pysamstats.pyx":94
 *             reads_pp += 1
 * 
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":95
 * 
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_pp': reads_pp}
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":96
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp}
 * 
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_all), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":97
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_pp': reads_pp}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_1construct_rec_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_1construct_rec_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_coverage (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__col,&__pyx_n_s__one_based,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__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_coverage", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_coverage") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[1]);
    if (values[2]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":65
 * 
 * 
 * cpdef object construct_rec_coverage(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_coverage", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_construct_rec_coverage(__pyx_self, __pyx_v_samfile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_construct_rec_coverage(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_coverage __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_coverage", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_coverage(__pyx_v_samfile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_3stat_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_3stat_coverage = {__Pyx_NAMESTR("stat_coverage"), (PyCFunction)__pyx_pw_10pysamstats_3stat_coverage, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_3stat_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_coverage (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__samfile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysamstats.pyx":100
 * 
 * 
 * def stat_coverage(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_1;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  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__chrom);
          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__one_based);
          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, "stat_coverage") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
    __pyx_v_one_based = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_2stat_coverage(__pyx_self, __pyx_v_samfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_2stat_coverage(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_coverage", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *)__pyx_ptype_10pysamstats___pyx_scope_struct__stat_coverage->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct__stat_coverage, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_4generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_4generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_coverage __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":101
 * 
 * def stat_coverage(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_coverage(samfile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":102
 * def stat_coverage(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_coverage(samfile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 102; __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 = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 102; __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 = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":103
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_coverage(samfile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_coverage(__pyx_cur_scope->__pyx_v_samfile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_coverage", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_6write_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_6write_coverage = {__Pyx_NAMESTR("write_coverage"), (PyCFunction)__pyx_pw_10pysamstats_6write_coverage, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_6write_coverage(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_coverage (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_coverage", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_5write_coverage(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":106
 * 
 * 
 * def write_coverage(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'reads_all', 'reads_pp')
 *     write_stats(stat_coverage, fieldnames, *args, **kwargs)
 */

static PyObject *__pyx_pf_10pysamstats_5write_coverage(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_coverage", 0);

  /* "pysamstats.pyx":107
 * 
 * def write_coverage(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'reads_all', 'reads_pp')             # <<<<<<<<<<<<<<
 *     write_stats(stat_coverage, fieldnames, *args, **kwargs)
 * 
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_2));
  __pyx_v_fieldnames = __pyx_k_tuple_2;

  /* "pysamstats.pyx":108
 * def write_coverage(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'reads_all', 'reads_pp')
 *     write_stats(stat_coverage, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_coverage); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_coverage", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":116
 * 
 * 
 * cpdef object construct_rec_coverage_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */

static PyObject *__pyx_pw_10pysamstats_8construct_rec_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_coverage_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_coverage_strand *__pyx_optional_args) {
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_reverse;
  int __pyx_v_is_proper_pair;
  unsigned int __pyx_v_reads_fwd;
  unsigned int __pyx_v_reads_rev;
  unsigned int __pyx_v_reads_pp;
  unsigned int __pyx_v_reads_pp_fwd;
  unsigned int __pyx_v_reads_pp_rev;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_coverage_strand", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":127
 *     cdef bint is_reverse
 *     cdef bint is_proper_pair
 *     cdef unsigned int reads_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_pp = 0
 */
  __pyx_v_reads_fwd = 0;

  /* "pysamstats.pyx":128
 *     cdef bint is_proper_pair
 *     cdef unsigned int reads_fwd = 0
 *     cdef unsigned int reads_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_fwd = 0
 */
  __pyx_v_reads_rev = 0;

  /* "pysamstats.pyx":129
 *     cdef unsigned int reads_fwd = 0
 *     cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_pp_rev = 0
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":130
 *     cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_rev = 0
 * 
 */
  __pyx_v_reads_pp_fwd = 0;

  /* "pysamstats.pyx":131
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_pp_rev = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_reads_pp_rev = 0;

  /* "pysamstats.pyx":134
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":135
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":138
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":139
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":142
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":143
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":144
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":145
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         if is_reverse:
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":146
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)             # <<<<<<<<<<<<<<
 *         if is_reverse:
 *             reads_rev += 1
 */
    __pyx_v_is_reverse = ((int)(__pyx_v_flag & 16));

    /* "pysamstats.pyx":147
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         if is_reverse:             # <<<<<<<<<<<<<<
 *             reads_rev += 1
 *         else:
 */
    if (__pyx_v_is_reverse) {

      /* "pysamstats.pyx":148
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         if is_reverse:
 *             reads_rev += 1             # <<<<<<<<<<<<<<
 *         else:
 *             reads_fwd += 1
 */
      __pyx_v_reads_rev = (__pyx_v_reads_rev + 1);
      goto __pyx_L5;
    }
    /*else*/ {

      /* "pysamstats.pyx":150
 *             reads_rev += 1
 *         else:
 *             reads_fwd += 1             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:
 */
      __pyx_v_reads_fwd = (__pyx_v_reads_fwd + 1);
    }
    __pyx_L5:;

    /* "pysamstats.pyx":151
 *         else:
 *             reads_fwd += 1
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         if is_proper_pair:
 *             reads_pp += 1
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":152
 *             reads_fwd += 1
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *             if is_reverse:
 */
    if (__pyx_v_is_proper_pair) {

      /* "pysamstats.pyx":153
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:
 *             reads_pp += 1             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_pp_rev += 1
 */
      __pyx_v_reads_pp = (__pyx_v_reads_pp + 1);

      /* "pysamstats.pyx":154
 *         if is_proper_pair:
 *             reads_pp += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_pp_rev += 1
 *             else:
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":155
 *             reads_pp += 1
 *             if is_reverse:
 *                 reads_pp_rev += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_pp_fwd += 1
 */
        __pyx_v_reads_pp_rev = (__pyx_v_reads_pp_rev + 1);
        goto __pyx_L7;
      }
      /*else*/ {

        /* "pysamstats.pyx":157
 *                 reads_pp_rev += 1
 *             else:
 *                 reads_pp_fwd += 1             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom,
 */
        __pyx_v_reads_pp_fwd = (__pyx_v_reads_pp_fwd + 1);
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "pysamstats.pyx":159
 *                 reads_pp_fwd += 1
 * 
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":160
 * 
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 160; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":161
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_all), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":162
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,             # <<<<<<<<<<<<<<
 *             'reads_rev': reads_rev,
 *             'reads_pp': reads_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":163
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":164
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,
 *             'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *             'reads_pp_fwd': reads_pp_fwd,
 *             'reads_pp_rev': reads_pp_rev}
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":165
 *             'reads_rev': reads_rev,
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,             # <<<<<<<<<<<<<<
 *             'reads_pp_rev': reads_pp_rev}
 * 
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":166
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,
 *             'reads_pp_rev': reads_pp_rev}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 166; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_8construct_rec_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_8construct_rec_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_coverage_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__col,&__pyx_n_s__one_based,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__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_coverage_strand", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_coverage_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[1]);
    if (values[2]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":116
 * 
 * 
 * cpdef object construct_rec_coverage_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_coverage_strand", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_7construct_rec_coverage_strand(__pyx_self, __pyx_v_samfile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_7construct_rec_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_coverage_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_coverage_strand", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_coverage_strand(__pyx_v_samfile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_11generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_10stat_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_10stat_coverage_strand = {__Pyx_NAMESTR("stat_coverage_strand"), (PyCFunction)__pyx_pw_10pysamstats_10stat_coverage_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_10stat_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_coverage_strand (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__samfile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysamstats.pyx":169
 * 
 * 
 * def stat_coverage_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_3;
    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__chrom);
          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__one_based);
          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, "stat_coverage_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
    __pyx_v_one_based = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_strand", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_coverage_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_9stat_coverage_strand(__pyx_self, __pyx_v_samfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_9stat_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_coverage_strand", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *)__pyx_ptype_10pysamstats___pyx_scope_struct_1_stat_coverage_strand->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_1_stat_coverage_strand, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_11generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_coverage_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_11generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_coverage_strand __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":170
 * 
 * def stat_coverage_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(chrom, start, end):
 *         yield construct_rec_coverage_strand(samfile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":171
 * def stat_coverage_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_coverage_strand(samfile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 171; __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 = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 171; __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 = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":172
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 *         yield construct_rec_coverage_strand(samfile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_coverage_strand(__pyx_cur_scope->__pyx_v_samfile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_coverage_strand", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_13write_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_13write_coverage_strand = {__Pyx_NAMESTR("write_coverage_strand"), (PyCFunction)__pyx_pw_10pysamstats_13write_coverage_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_13write_coverage_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_coverage_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_coverage_strand", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_12write_coverage_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":175
 * 
 * 
 * def write_coverage_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all', 'reads_fwd', 'reads_rev',
 */

static PyObject *__pyx_pf_10pysamstats_12write_coverage_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_coverage_strand", 0);

  /* "pysamstats.pyx":176
 * 
 * def write_coverage_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *                   'reads_all', 'reads_fwd', 'reads_rev',
 *                   'reads_pp', 'reads_pp_fwd', 'reads_pp_rev')
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_4));
  __pyx_v_fieldnames = __pyx_k_tuple_4;

  /* "pysamstats.pyx":179
 *                   'reads_all', 'reads_fwd', 'reads_rev',
 *                   'reads_pp', 'reads_pp_fwd', 'reads_pp_rev')
 *     write_stats(stat_coverage_strand, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s_5); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_coverage_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":187
 * 
 * 
 * cpdef object construct_rec_coverage_ext(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */

static PyObject *__pyx_pw_10pysamstats_15construct_rec_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_coverage_ext(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext *__pyx_optional_args) {
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  int __pyx_v_is_reverse;
  int __pyx_v_is_proper_pair;
  int __pyx_v_is_duplicate;
  int __pyx_v_mate_is_reverse;
  int __pyx_v_tlen;
  unsigned int __pyx_v_reads_pp;
  unsigned int __pyx_v_reads_mate_unmapped;
  unsigned int __pyx_v_reads_mate_other_chr;
  unsigned int __pyx_v_reads_mate_same_strand;
  unsigned int __pyx_v_reads_faceaway;
  unsigned int __pyx_v_reads_softclipped;
  unsigned int __pyx_v_reads_duplicate;
  int __pyx_v_tid;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  uint32_t __pyx_v_flag;
  int __pyx_v_mate_is_unmapped;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int32_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_coverage_ext", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":202
 *     cdef int tlen
 *     # counting variables
 *     cdef unsigned int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_unmapped = 0
 *     cdef unsigned int reads_mate_other_chr = 0
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":203
 *     # counting variables
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_mate_unmapped = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_other_chr = 0
 *     cdef unsigned int reads_mate_same_strand = 0
 */
  __pyx_v_reads_mate_unmapped = 0;

  /* "pysamstats.pyx":204
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_mate_unmapped = 0
 *     cdef unsigned int reads_mate_other_chr = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_same_strand = 0
 *     cdef unsigned int reads_faceaway = 0
 */
  __pyx_v_reads_mate_other_chr = 0;

  /* "pysamstats.pyx":205
 *     cdef unsigned int reads_mate_unmapped = 0
 *     cdef unsigned int reads_mate_other_chr = 0
 *     cdef unsigned int reads_mate_same_strand = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_faceaway = 0
 *     cdef unsigned int reads_softclipped = 0
 */
  __pyx_v_reads_mate_same_strand = 0;

  /* "pysamstats.pyx":206
 *     cdef unsigned int reads_mate_other_chr = 0
 *     cdef unsigned int reads_mate_same_strand = 0
 *     cdef unsigned int reads_faceaway = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_softclipped = 0
 *     cdef unsigned int reads_duplicate = 0
 */
  __pyx_v_reads_faceaway = 0;

  /* "pysamstats.pyx":207
 *     cdef unsigned int reads_mate_same_strand = 0
 *     cdef unsigned int reads_faceaway = 0
 *     cdef unsigned int reads_softclipped = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_duplicate = 0
 * 
 */
  __pyx_v_reads_softclipped = 0;

  /* "pysamstats.pyx":208
 *     cdef unsigned int reads_faceaway = 0
 *     cdef unsigned int reads_softclipped = 0
 *     cdef unsigned int reads_duplicate = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_reads_duplicate = 0;

  /* "pysamstats.pyx":211
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":212
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":215
 * 
 *     # get chromosome name and position
 *     tid = col.tid             # <<<<<<<<<<<<<<
 *     chrom = samfile.getrname(tid)
 *     pos = col.pos + 1 if one_based else col.pos
 */
  __pyx_t_2 = __pyx_v_col->tid;
  __pyx_v_tid = __pyx_t_2;

  /* "pysamstats.pyx":216
 *     # get chromosome name and position
 *     tid = col.tid
 *     chrom = samfile.getrname(tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":217
 *     tid = col.tid
 *     chrom = samfile.getrname(tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":220
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":221
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":222
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":223
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":224
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_duplicate = <bint>(flag & BAM_FDUP)
 */
    __pyx_v_is_reverse = ((int)(__pyx_v_flag & 16));

    /* "pysamstats.pyx":225
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         is_duplicate = <bint>(flag & BAM_FDUP)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":226
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_duplicate = <bint>(flag & BAM_FDUP)             # <<<<<<<<<<<<<<
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_is_reverse = <bint>(flag & BAM_FMREVERSE)
 */
    __pyx_v_is_duplicate = ((int)(__pyx_v_flag & 1024));

    /* "pysamstats.pyx":227
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_duplicate = <bint>(flag & BAM_FDUP)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)             # <<<<<<<<<<<<<<
 *         mate_is_reverse = <bint>(flag & BAM_FMREVERSE)
 *         tlen = aln.core.isize
 */
    __pyx_v_mate_is_unmapped = ((int)(__pyx_v_flag & 8));

    /* "pysamstats.pyx":228
 *         is_duplicate = <bint>(flag & BAM_FDUP)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_is_reverse = <bint>(flag & BAM_FMREVERSE)             # <<<<<<<<<<<<<<
 *         tlen = aln.core.isize
 *         if is_duplicate:
 */
    __pyx_v_mate_is_reverse = ((int)(__pyx_v_flag & 32));

    /* "pysamstats.pyx":229
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_is_reverse = <bint>(flag & BAM_FMREVERSE)
 *         tlen = aln.core.isize             # <<<<<<<<<<<<<<
 *         if is_duplicate:
 *             reads_duplicate += 1
 */
    __pyx_t_10 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_10;

    /* "pysamstats.pyx":230
 *         mate_is_reverse = <bint>(flag & BAM_FMREVERSE)
 *         tlen = aln.core.isize
 *         if is_duplicate:             # <<<<<<<<<<<<<<
 *             reads_duplicate += 1
 *         if is_proper_pair:
 */
    if (__pyx_v_is_duplicate) {

      /* "pysamstats.pyx":231
 *         tlen = aln.core.isize
 *         if is_duplicate:
 *             reads_duplicate += 1             # <<<<<<<<<<<<<<
 *         if is_proper_pair:
 *             reads_pp += 1
 */
      __pyx_v_reads_duplicate = (__pyx_v_reads_duplicate + 1);
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "pysamstats.pyx":232
 *         if is_duplicate:
 *             reads_duplicate += 1
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *         if mate_is_unmapped:
 */
    if (__pyx_v_is_proper_pair) {

      /* "pysamstats.pyx":233
 *             reads_duplicate += 1
 *         if is_proper_pair:
 *             reads_pp += 1             # <<<<<<<<<<<<<<
 *         if mate_is_unmapped:
 *             reads_mate_unmapped += 1
 */
      __pyx_v_reads_pp = (__pyx_v_reads_pp + 1);
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysamstats.pyx":234
 *         if is_proper_pair:
 *             reads_pp += 1
 *         if mate_is_unmapped:             # <<<<<<<<<<<<<<
 *             reads_mate_unmapped += 1
 *         elif tid != aln.core.mtid:
 */
    if (__pyx_v_mate_is_unmapped) {

      /* "pysamstats.pyx":235
 *             reads_pp += 1
 *         if mate_is_unmapped:
 *             reads_mate_unmapped += 1             # <<<<<<<<<<<<<<
 *         elif tid != aln.core.mtid:
 *             reads_mate_other_chr += 1
 */
      __pyx_v_reads_mate_unmapped = (__pyx_v_reads_mate_unmapped + 1);
      goto __pyx_L7;
    }

    /* "pysamstats.pyx":236
 *         if mate_is_unmapped:
 *             reads_mate_unmapped += 1
 *         elif tid != aln.core.mtid:             # <<<<<<<<<<<<<<
 *             reads_mate_other_chr += 1
 *         elif (is_reverse and mate_is_reverse) or (not is_reverse and not mate_is_reverse):
 */
    __pyx_t_11 = (__pyx_v_tid != __pyx_v_aln->core.mtid);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":237
 *             reads_mate_unmapped += 1
 *         elif tid != aln.core.mtid:
 *             reads_mate_other_chr += 1             # <<<<<<<<<<<<<<
 *         elif (is_reverse and mate_is_reverse) or (not is_reverse and not mate_is_reverse):
 *             reads_mate_same_strand += 1
 */
      __pyx_v_reads_mate_other_chr = (__pyx_v_reads_mate_other_chr + 1);
      goto __pyx_L7;
    }

    /* "pysamstats.pyx":238
 *         elif tid != aln.core.mtid:
 *             reads_mate_other_chr += 1
 *         elif (is_reverse and mate_is_reverse) or (not is_reverse and not mate_is_reverse):             # <<<<<<<<<<<<<<
 *             reads_mate_same_strand += 1
 *         elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 */
    if (__pyx_v_is_reverse) {
      __pyx_t_11 = __pyx_v_mate_is_reverse;
    } else {
      __pyx_t_11 = __pyx_v_is_reverse;
    }
    if (!__pyx_t_11) {
      __pyx_t_12 = (!__pyx_v_is_reverse);
      if (__pyx_t_12) {
        __pyx_t_13 = (!__pyx_v_mate_is_reverse);
        __pyx_t_14 = __pyx_t_13;
      } else {
        __pyx_t_14 = __pyx_t_12;
      }
      __pyx_t_12 = __pyx_t_14;
    } else {
      __pyx_t_12 = __pyx_t_11;
    }
    if (__pyx_t_12) {

      /* "pysamstats.pyx":239
 *             reads_mate_other_chr += 1
 *         elif (is_reverse and mate_is_reverse) or (not is_reverse and not mate_is_reverse):
 *             reads_mate_same_strand += 1             # <<<<<<<<<<<<<<
 *         elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 *             reads_faceaway += 1
 */
      __pyx_v_reads_mate_same_strand = (__pyx_v_reads_mate_same_strand + 1);
      goto __pyx_L7;
    }

    /* "pysamstats.pyx":240
 *         elif (is_reverse and mate_is_reverse) or (not is_reverse and not mate_is_reverse):
 *             reads_mate_same_strand += 1
 *         elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):             # <<<<<<<<<<<<<<
 *             reads_faceaway += 1
 *         if is_softclipped(aln):
 */
    if (__pyx_v_is_reverse) {
      __pyx_t_12 = (__pyx_v_tlen > 0);
      __pyx_t_11 = __pyx_t_12;
    } else {
      __pyx_t_11 = __pyx_v_is_reverse;
    }
    if (!__pyx_t_11) {
      __pyx_t_12 = (!__pyx_v_is_reverse);
      if (__pyx_t_12) {
        __pyx_t_14 = (__pyx_v_tlen < 0);
        __pyx_t_13 = __pyx_t_14;
      } else {
        __pyx_t_13 = __pyx_t_12;
      }
      __pyx_t_12 = __pyx_t_13;
    } else {
      __pyx_t_12 = __pyx_t_11;
    }
    if (__pyx_t_12) {

      /* "pysamstats.pyx":241
 *             reads_mate_same_strand += 1
 *         elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 *             reads_faceaway += 1             # <<<<<<<<<<<<<<
 *         if is_softclipped(aln):
 *             reads_softclipped += 1
 */
      __pyx_v_reads_faceaway = (__pyx_v_reads_faceaway + 1);
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "pysamstats.pyx":242
 *         elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 *             reads_faceaway += 1
 *         if is_softclipped(aln):             # <<<<<<<<<<<<<<
 *             reads_softclipped += 1
 * 
 */
    __pyx_t_12 = __pyx_f_10pysamstats_is_softclipped(__pyx_v_aln);
    if (__pyx_t_12) {

      /* "pysamstats.pyx":243
 *             reads_faceaway += 1
 *         if is_softclipped(aln):
 *             reads_softclipped += 1             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom, 'pos': pos,
 */
      __pyx_v_reads_softclipped = (__pyx_v_reads_softclipped + 1);
      goto __pyx_L8;
    }
    __pyx_L8:;
  }

  /* "pysamstats.pyx":245
 *             reads_softclipped += 1
 * 
 *     return {'chrom': chrom, 'pos': pos,             # <<<<<<<<<<<<<<
 *                'reads_all': n,
 *                'reads_pp': reads_pp,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":246
 * 
 *     return {'chrom': chrom, 'pos': pos,
 *                'reads_all': n,             # <<<<<<<<<<<<<<
 *                'reads_pp': reads_pp,
 *                'reads_mate_unmapped': reads_mate_unmapped,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_all), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":247
 *     return {'chrom': chrom, 'pos': pos,
 *                'reads_all': n,
 *                'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *                'reads_mate_unmapped': reads_mate_unmapped,
 *                'reads_mate_other_chr': reads_mate_other_chr,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":248
 *                'reads_all': n,
 *                'reads_pp': reads_pp,
 *                'reads_mate_unmapped': reads_mate_unmapped,             # <<<<<<<<<<<<<<
 *                'reads_mate_other_chr': reads_mate_other_chr,
 *                'reads_mate_same_strand': reads_mate_same_strand,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_unmapped); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_mate_unmapped), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":249
 *                'reads_pp': reads_pp,
 *                'reads_mate_unmapped': reads_mate_unmapped,
 *                'reads_mate_other_chr': reads_mate_other_chr,             # <<<<<<<<<<<<<<
 *                'reads_mate_same_strand': reads_mate_same_strand,
 *                'reads_faceaway': reads_faceaway,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_other_chr); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_6), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":250
 *                'reads_mate_unmapped': reads_mate_unmapped,
 *                'reads_mate_other_chr': reads_mate_other_chr,
 *                'reads_mate_same_strand': reads_mate_same_strand,             # <<<<<<<<<<<<<<
 *                'reads_faceaway': reads_faceaway,
 *                'reads_softclipped': reads_softclipped,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_same_strand); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_7), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":251
 *                'reads_mate_other_chr': reads_mate_other_chr,
 *                'reads_mate_same_strand': reads_mate_same_strand,
 *                'reads_faceaway': reads_faceaway,             # <<<<<<<<<<<<<<
 *                'reads_softclipped': reads_softclipped,
 *                'reads_duplicate': reads_duplicate}
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_faceaway); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_faceaway), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":252
 *                'reads_mate_same_strand': reads_mate_same_strand,
 *                'reads_faceaway': reads_faceaway,
 *                'reads_softclipped': reads_softclipped,             # <<<<<<<<<<<<<<
 *                'reads_duplicate': reads_duplicate}
 * 
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_softclipped); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_softclipped), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":253
 *                'reads_faceaway': reads_faceaway,
 *                'reads_softclipped': reads_softclipped,
 *                'reads_duplicate': reads_duplicate}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_duplicate); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 253; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_duplicate), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_15construct_rec_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_15construct_rec_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_coverage_ext (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__col,&__pyx_n_s__one_based,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__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_coverage_ext", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_coverage_ext") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[1]);
    if (values[2]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":187
 * 
 * 
 * cpdef object construct_rec_coverage_ext(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_coverage_ext", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_14construct_rec_coverage_ext(__pyx_self, __pyx_v_samfile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_14construct_rec_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_coverage_ext", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_coverage_ext(__pyx_v_samfile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_18generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_17stat_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_17stat_coverage_ext = {__Pyx_NAMESTR("stat_coverage_ext"), (PyCFunction)__pyx_pw_10pysamstats_17stat_coverage_ext, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_17stat_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_coverage_ext (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__samfile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysamstats.pyx":256
 * 
 * 
 * def stat_coverage_ext(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_8;
    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__chrom);
          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__one_based);
          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, "stat_coverage_ext") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
    __pyx_v_one_based = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_ext", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_coverage_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_16stat_coverage_ext(__pyx_self, __pyx_v_samfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_16stat_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_coverage_ext", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *)__pyx_ptype_10pysamstats___pyx_scope_struct_2_stat_coverage_ext->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_2_stat_coverage_ext, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_18generator2, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_coverage_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_18generator2(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":257
 * 
 * def stat_coverage_ext(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(chrom, start, end):
 *         yield construct_rec_coverage_ext(samfile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":258
 * def stat_coverage_ext(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_coverage_ext(samfile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 258; __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 = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 258; __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 = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 258; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":259
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 *         yield construct_rec_coverage_ext(samfile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_coverage_ext(__pyx_cur_scope->__pyx_v_samfile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_coverage_ext", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_20write_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_20write_coverage_ext = {__Pyx_NAMESTR("write_coverage_ext"), (PyCFunction)__pyx_pw_10pysamstats_20write_coverage_ext, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_20write_coverage_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_coverage_ext (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_coverage_ext", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_19write_coverage_ext(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":262
 * 
 * 
 * def write_coverage_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all',
 */

static PyObject *__pyx_pf_10pysamstats_19write_coverage_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_coverage_ext", 0);

  /* "pysamstats.pyx":263
 * 
 * def write_coverage_ext(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *                   'reads_all',
 *                   'reads_pp',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_9));
  __pyx_v_fieldnames = __pyx_k_tuple_9;

  /* "pysamstats.pyx":272
 *                   'reads_softclipped',
 *                   'reads_duplicate')
 *     write_stats(stat_coverage_ext, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_coverage_ext); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; __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 = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 272; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_coverage_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":280
 * 
 * 
 * cpdef object construct_rec_coverage_ext_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */

static PyObject *__pyx_pw_10pysamstats_22construct_rec_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_coverage_ext_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext_strand *__pyx_optional_args) {
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  int __pyx_v_is_reverse;
  int __pyx_v_is_proper_pair;
  int __pyx_v_is_duplicate;
  int __pyx_v_mate_is_reverse;
  int __pyx_v_tlen;
  unsigned int __pyx_v_reads_rev;
  unsigned int __pyx_v_reads_fwd;
  unsigned int __pyx_v_reads_pp;
  unsigned int __pyx_v_reads_pp_rev;
  unsigned int __pyx_v_reads_pp_fwd;
  unsigned int __pyx_v_reads_mate_unmapped;
  unsigned int __pyx_v_reads_mate_unmapped_rev;
  unsigned int __pyx_v_reads_mate_unmapped_fwd;
  unsigned int __pyx_v_reads_mate_other_chr;
  unsigned int __pyx_v_reads_mate_other_chr_rev;
  unsigned int __pyx_v_reads_mate_other_chr_fwd;
  unsigned int __pyx_v_reads_mate_same_strand;
  unsigned int __pyx_v_reads_mate_same_strand_rev;
  unsigned int __pyx_v_reads_mate_same_strand_fwd;
  unsigned int __pyx_v_reads_faceaway;
  unsigned int __pyx_v_reads_faceaway_rev;
  unsigned int __pyx_v_reads_faceaway_fwd;
  unsigned int __pyx_v_reads_softclipped;
  unsigned int __pyx_v_reads_softclipped_rev;
  unsigned int __pyx_v_reads_softclipped_fwd;
  unsigned int __pyx_v_reads_duplicate;
  unsigned int __pyx_v_reads_duplicate_rev;
  unsigned int __pyx_v_reads_duplicate_fwd;
  int __pyx_v_tid;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  uint32_t __pyx_v_flag;
  int __pyx_v_mate_is_unmapped;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int32_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_coverage_ext_strand", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":295
 *     cdef int tlen
 *     # counting variables
 *     cdef unsigned int reads_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_fwd = 0
 *     cdef unsigned int reads_pp = 0
 */
  __pyx_v_reads_rev = 0;

  /* "pysamstats.pyx":296
 *     # counting variables
 *     cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_rev = 0
 */
  __pyx_v_reads_fwd = 0;

  /* "pysamstats.pyx":297
 *     cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_fwd = 0
 *     cdef unsigned int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_rev = 0
 *     cdef unsigned int reads_pp_fwd = 0
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":298
 *     cdef unsigned int reads_fwd = 0
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_mate_unmapped = 0
 */
  __pyx_v_reads_pp_rev = 0;

  /* "pysamstats.pyx":299
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_rev = 0
 *     cdef unsigned int reads_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_unmapped = 0
 *     cdef unsigned int reads_mate_unmapped_rev = 0
 */
  __pyx_v_reads_pp_fwd = 0;

  /* "pysamstats.pyx":300
 *     cdef unsigned int reads_pp_rev = 0
 *     cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_mate_unmapped = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_unmapped_rev = 0
 *     cdef unsigned int reads_mate_unmapped_fwd = 0
 */
  __pyx_v_reads_mate_unmapped = 0;

  /* "pysamstats.pyx":301
 *     cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_mate_unmapped = 0
 *     cdef unsigned int reads_mate_unmapped_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_unmapped_fwd = 0
 *     cdef unsigned int reads_mate_other_chr = 0
 */
  __pyx_v_reads_mate_unmapped_rev = 0;

  /* "pysamstats.pyx":302
 *     cdef unsigned int reads_mate_unmapped = 0
 *     cdef unsigned int reads_mate_unmapped_rev = 0
 *     cdef unsigned int reads_mate_unmapped_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_other_chr = 0
 *     cdef unsigned int reads_mate_other_chr_rev = 0
 */
  __pyx_v_reads_mate_unmapped_fwd = 0;

  /* "pysamstats.pyx":303
 *     cdef unsigned int reads_mate_unmapped_rev = 0
 *     cdef unsigned int reads_mate_unmapped_fwd = 0
 *     cdef unsigned int reads_mate_other_chr = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_other_chr_rev = 0
 *     cdef unsigned int reads_mate_other_chr_fwd = 0
 */
  __pyx_v_reads_mate_other_chr = 0;

  /* "pysamstats.pyx":304
 *     cdef unsigned int reads_mate_unmapped_fwd = 0
 *     cdef unsigned int reads_mate_other_chr = 0
 *     cdef unsigned int reads_mate_other_chr_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_other_chr_fwd = 0
 *     cdef unsigned int reads_mate_same_strand = 0
 */
  __pyx_v_reads_mate_other_chr_rev = 0;

  /* "pysamstats.pyx":305
 *     cdef unsigned int reads_mate_other_chr = 0
 *     cdef unsigned int reads_mate_other_chr_rev = 0
 *     cdef unsigned int reads_mate_other_chr_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_same_strand = 0
 *     cdef unsigned int reads_mate_same_strand_rev = 0
 */
  __pyx_v_reads_mate_other_chr_fwd = 0;

  /* "pysamstats.pyx":306
 *     cdef unsigned int reads_mate_other_chr_rev = 0
 *     cdef unsigned int reads_mate_other_chr_fwd = 0
 *     cdef unsigned int reads_mate_same_strand = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_same_strand_rev = 0
 *     cdef unsigned int reads_mate_same_strand_fwd = 0
 */
  __pyx_v_reads_mate_same_strand = 0;

  /* "pysamstats.pyx":307
 *     cdef unsigned int reads_mate_other_chr_fwd = 0
 *     cdef unsigned int reads_mate_same_strand = 0
 *     cdef unsigned int reads_mate_same_strand_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mate_same_strand_fwd = 0
 *     cdef unsigned int reads_faceaway = 0
 */
  __pyx_v_reads_mate_same_strand_rev = 0;

  /* "pysamstats.pyx":308
 *     cdef unsigned int reads_mate_same_strand = 0
 *     cdef unsigned int reads_mate_same_strand_rev = 0
 *     cdef unsigned int reads_mate_same_strand_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_faceaway = 0
 *     cdef unsigned int reads_faceaway_rev = 0
 */
  __pyx_v_reads_mate_same_strand_fwd = 0;

  /* "pysamstats.pyx":309
 *     cdef unsigned int reads_mate_same_strand_rev = 0
 *     cdef unsigned int reads_mate_same_strand_fwd = 0
 *     cdef unsigned int reads_faceaway = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_faceaway_rev = 0
 *     cdef unsigned int reads_faceaway_fwd = 0
 */
  __pyx_v_reads_faceaway = 0;

  /* "pysamstats.pyx":310
 *     cdef unsigned int reads_mate_same_strand_fwd = 0
 *     cdef unsigned int reads_faceaway = 0
 *     cdef unsigned int reads_faceaway_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_faceaway_fwd = 0
 *     cdef unsigned int reads_softclipped = 0
 */
  __pyx_v_reads_faceaway_rev = 0;

  /* "pysamstats.pyx":311
 *     cdef unsigned int reads_faceaway = 0
 *     cdef unsigned int reads_faceaway_rev = 0
 *     cdef unsigned int reads_faceaway_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_softclipped = 0
 *     cdef unsigned int reads_softclipped_rev = 0
 */
  __pyx_v_reads_faceaway_fwd = 0;

  /* "pysamstats.pyx":312
 *     cdef unsigned int reads_faceaway_rev = 0
 *     cdef unsigned int reads_faceaway_fwd = 0
 *     cdef unsigned int reads_softclipped = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_softclipped_rev = 0
 *     cdef unsigned int reads_softclipped_fwd = 0
 */
  __pyx_v_reads_softclipped = 0;

  /* "pysamstats.pyx":313
 *     cdef unsigned int reads_faceaway_fwd = 0
 *     cdef unsigned int reads_softclipped = 0
 *     cdef unsigned int reads_softclipped_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_softclipped_fwd = 0
 *     cdef unsigned int reads_duplicate = 0
 */
  __pyx_v_reads_softclipped_rev = 0;

  /* "pysamstats.pyx":314
 *     cdef unsigned int reads_softclipped = 0
 *     cdef unsigned int reads_softclipped_rev = 0
 *     cdef unsigned int reads_softclipped_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_duplicate = 0
 *     cdef unsigned int reads_duplicate_rev = 0
 */
  __pyx_v_reads_softclipped_fwd = 0;

  /* "pysamstats.pyx":315
 *     cdef unsigned int reads_softclipped_rev = 0
 *     cdef unsigned int reads_softclipped_fwd = 0
 *     cdef unsigned int reads_duplicate = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_duplicate_rev = 0
 *     cdef unsigned int reads_duplicate_fwd = 0
 */
  __pyx_v_reads_duplicate = 0;

  /* "pysamstats.pyx":316
 *     cdef unsigned int reads_softclipped_fwd = 0
 *     cdef unsigned int reads_duplicate = 0
 *     cdef unsigned int reads_duplicate_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_duplicate_fwd = 0
 * 
 */
  __pyx_v_reads_duplicate_rev = 0;

  /* "pysamstats.pyx":317
 *     cdef unsigned int reads_duplicate = 0
 *     cdef unsigned int reads_duplicate_rev = 0
 *     cdef unsigned int reads_duplicate_fwd = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_reads_duplicate_fwd = 0;

  /* "pysamstats.pyx":320
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 320; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":321
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":324
 * 
 *     # get chromosome name and position
 *     tid = col.tid             # <<<<<<<<<<<<<<
 *     chrom = samfile.getrname(tid)
 *     pos = col.pos + 1 if one_based else col.pos
 */
  __pyx_t_2 = __pyx_v_col->tid;
  __pyx_v_tid = __pyx_t_2;

  /* "pysamstats.pyx":325
 *     # get chromosome name and position
 *     tid = col.tid
 *     chrom = samfile.getrname(tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 325; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":326
 *     tid = col.tid
 *     chrom = samfile.getrname(tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":329
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":330
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":331
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":332
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":333
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_duplicate = <bint>(flag & BAM_FDUP)
 */
    __pyx_v_is_reverse = ((int)(__pyx_v_flag & 16));

    /* "pysamstats.pyx":334
 *         flag = aln.core.flag
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         is_duplicate = <bint>(flag & BAM_FDUP)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":335
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_duplicate = <bint>(flag & BAM_FDUP)             # <<<<<<<<<<<<<<
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_is_reverse = <bint>(flag & BAM_FMREVERSE)
 */
    __pyx_v_is_duplicate = ((int)(__pyx_v_flag & 1024));

    /* "pysamstats.pyx":336
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_duplicate = <bint>(flag & BAM_FDUP)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)             # <<<<<<<<<<<<<<
 *         mate_is_reverse = <bint>(flag & BAM_FMREVERSE)
 *         tlen = aln.core.isize
 */
    __pyx_v_mate_is_unmapped = ((int)(__pyx_v_flag & 8));

    /* "pysamstats.pyx":337
 *         is_duplicate = <bint>(flag & BAM_FDUP)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_is_reverse = <bint>(flag & BAM_FMREVERSE)             # <<<<<<<<<<<<<<
 *         tlen = aln.core.isize
 *         if is_reverse:
 */
    __pyx_v_mate_is_reverse = ((int)(__pyx_v_flag & 32));

    /* "pysamstats.pyx":338
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_is_reverse = <bint>(flag & BAM_FMREVERSE)
 *         tlen = aln.core.isize             # <<<<<<<<<<<<<<
 *         if is_reverse:
 *             reads_rev += 1
 */
    __pyx_t_10 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_10;

    /* "pysamstats.pyx":339
 *         mate_is_reverse = <bint>(flag & BAM_FMREVERSE)
 *         tlen = aln.core.isize
 *         if is_reverse:             # <<<<<<<<<<<<<<
 *             reads_rev += 1
 *         else:
 */
    if (__pyx_v_is_reverse) {

      /* "pysamstats.pyx":340
 *         tlen = aln.core.isize
 *         if is_reverse:
 *             reads_rev += 1             # <<<<<<<<<<<<<<
 *         else:
 *             reads_fwd += 1
 */
      __pyx_v_reads_rev = (__pyx_v_reads_rev + 1);
      goto __pyx_L5;
    }
    /*else*/ {

      /* "pysamstats.pyx":342
 *             reads_rev += 1
 *         else:
 *             reads_fwd += 1             # <<<<<<<<<<<<<<
 *         if is_proper_pair:
 *             reads_pp += 1
 */
      __pyx_v_reads_fwd = (__pyx_v_reads_fwd + 1);
    }
    __pyx_L5:;

    /* "pysamstats.pyx":343
 *         else:
 *             reads_fwd += 1
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *             if is_reverse:
 */
    if (__pyx_v_is_proper_pair) {

      /* "pysamstats.pyx":344
 *             reads_fwd += 1
 *         if is_proper_pair:
 *             reads_pp += 1             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_pp_rev += 1
 */
      __pyx_v_reads_pp = (__pyx_v_reads_pp + 1);

      /* "pysamstats.pyx":345
 *         if is_proper_pair:
 *             reads_pp += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_pp_rev += 1
 *             else:
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":346
 *             reads_pp += 1
 *             if is_reverse:
 *                 reads_pp_rev += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_pp_fwd += 1
 */
        __pyx_v_reads_pp_rev = (__pyx_v_reads_pp_rev + 1);
        goto __pyx_L7;
      }
      /*else*/ {

        /* "pysamstats.pyx":348
 *                 reads_pp_rev += 1
 *             else:
 *                 reads_pp_fwd += 1             # <<<<<<<<<<<<<<
 *         if mate_is_unmapped:
 *             reads_mate_unmapped += 1
 */
        __pyx_v_reads_pp_fwd = (__pyx_v_reads_pp_fwd + 1);
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysamstats.pyx":349
 *             else:
 *                 reads_pp_fwd += 1
 *         if mate_is_unmapped:             # <<<<<<<<<<<<<<
 *             reads_mate_unmapped += 1
 *             if is_reverse:
 */
    if (__pyx_v_mate_is_unmapped) {

      /* "pysamstats.pyx":350
 *                 reads_pp_fwd += 1
 *         if mate_is_unmapped:
 *             reads_mate_unmapped += 1             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_mate_unmapped_rev += 1
 */
      __pyx_v_reads_mate_unmapped = (__pyx_v_reads_mate_unmapped + 1);

      /* "pysamstats.pyx":351
 *         if mate_is_unmapped:
 *             reads_mate_unmapped += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_mate_unmapped_rev += 1
 *             else:
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":352
 *             reads_mate_unmapped += 1
 *             if is_reverse:
 *                 reads_mate_unmapped_rev += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_mate_unmapped_fwd += 1
 */
        __pyx_v_reads_mate_unmapped_rev = (__pyx_v_reads_mate_unmapped_rev + 1);
        goto __pyx_L9;
      }
      /*else*/ {

        /* "pysamstats.pyx":354
 *                 reads_mate_unmapped_rev += 1
 *             else:
 *                 reads_mate_unmapped_fwd += 1             # <<<<<<<<<<<<<<
 *         elif tid != aln.core.mtid:
 *             reads_mate_other_chr += 1
 */
        __pyx_v_reads_mate_unmapped_fwd = (__pyx_v_reads_mate_unmapped_fwd + 1);
      }
      __pyx_L9:;
      goto __pyx_L8;
    }

    /* "pysamstats.pyx":355
 *             else:
 *                 reads_mate_unmapped_fwd += 1
 *         elif tid != aln.core.mtid:             # <<<<<<<<<<<<<<
 *             reads_mate_other_chr += 1
 *             if is_reverse:
 */
    __pyx_t_11 = (__pyx_v_tid != __pyx_v_aln->core.mtid);
    if (__pyx_t_11) {

      /* "pysamstats.pyx":356
 *                 reads_mate_unmapped_fwd += 1
 *         elif tid != aln.core.mtid:
 *             reads_mate_other_chr += 1             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_mate_other_chr_rev += 1
 */
      __pyx_v_reads_mate_other_chr = (__pyx_v_reads_mate_other_chr + 1);

      /* "pysamstats.pyx":357
 *         elif tid != aln.core.mtid:
 *             reads_mate_other_chr += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_mate_other_chr_rev += 1
 *             else:
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":358
 *             reads_mate_other_chr += 1
 *             if is_reverse:
 *                 reads_mate_other_chr_rev += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_mate_other_chr_fwd += 1
 */
        __pyx_v_reads_mate_other_chr_rev = (__pyx_v_reads_mate_other_chr_rev + 1);
        goto __pyx_L10;
      }
      /*else*/ {

        /* "pysamstats.pyx":360
 *                 reads_mate_other_chr_rev += 1
 *             else:
 *                 reads_mate_other_chr_fwd += 1             # <<<<<<<<<<<<<<
 *         elif is_reverse and mate_is_reverse:
 *             reads_mate_same_strand += 1
 */
        __pyx_v_reads_mate_other_chr_fwd = (__pyx_v_reads_mate_other_chr_fwd + 1);
      }
      __pyx_L10:;
      goto __pyx_L8;
    }

    /* "pysamstats.pyx":361
 *             else:
 *                 reads_mate_other_chr_fwd += 1
 *         elif is_reverse and mate_is_reverse:             # <<<<<<<<<<<<<<
 *             reads_mate_same_strand += 1
 *             reads_mate_same_strand_rev += 1
 */
    if (__pyx_v_is_reverse) {
      __pyx_t_11 = __pyx_v_mate_is_reverse;
    } else {
      __pyx_t_11 = __pyx_v_is_reverse;
    }
    if (__pyx_t_11) {

      /* "pysamstats.pyx":362
 *                 reads_mate_other_chr_fwd += 1
 *         elif is_reverse and mate_is_reverse:
 *             reads_mate_same_strand += 1             # <<<<<<<<<<<<<<
 *             reads_mate_same_strand_rev += 1
 *         elif not is_reverse and not mate_is_reverse:
 */
      __pyx_v_reads_mate_same_strand = (__pyx_v_reads_mate_same_strand + 1);

      /* "pysamstats.pyx":363
 *         elif is_reverse and mate_is_reverse:
 *             reads_mate_same_strand += 1
 *             reads_mate_same_strand_rev += 1             # <<<<<<<<<<<<<<
 *         elif not is_reverse and not mate_is_reverse:
 *             reads_mate_same_strand += 1
 */
      __pyx_v_reads_mate_same_strand_rev = (__pyx_v_reads_mate_same_strand_rev + 1);
      goto __pyx_L8;
    }

    /* "pysamstats.pyx":364
 *             reads_mate_same_strand += 1
 *             reads_mate_same_strand_rev += 1
 *         elif not is_reverse and not mate_is_reverse:             # <<<<<<<<<<<<<<
 *             reads_mate_same_strand += 1
 *             reads_mate_same_strand_fwd += 1
 */
    __pyx_t_11 = (!__pyx_v_is_reverse);
    if (__pyx_t_11) {
      __pyx_t_12 = (!__pyx_v_mate_is_reverse);
      __pyx_t_13 = __pyx_t_12;
    } else {
      __pyx_t_13 = __pyx_t_11;
    }
    if (__pyx_t_13) {

      /* "pysamstats.pyx":365
 *             reads_mate_same_strand_rev += 1
 *         elif not is_reverse and not mate_is_reverse:
 *             reads_mate_same_strand += 1             # <<<<<<<<<<<<<<
 *             reads_mate_same_strand_fwd += 1
 *         elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 */
      __pyx_v_reads_mate_same_strand = (__pyx_v_reads_mate_same_strand + 1);

      /* "pysamstats.pyx":366
 *         elif not is_reverse and not mate_is_reverse:
 *             reads_mate_same_strand += 1
 *             reads_mate_same_strand_fwd += 1             # <<<<<<<<<<<<<<
 *         elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 *             reads_faceaway += 1
 */
      __pyx_v_reads_mate_same_strand_fwd = (__pyx_v_reads_mate_same_strand_fwd + 1);
      goto __pyx_L8;
    }

    /* "pysamstats.pyx":367
 *             reads_mate_same_strand += 1
 *             reads_mate_same_strand_fwd += 1
 *         elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):             # <<<<<<<<<<<<<<
 *             reads_faceaway += 1
 *             if is_reverse:
 */
    if (__pyx_v_is_reverse) {
      __pyx_t_13 = (__pyx_v_tlen > 0);
      __pyx_t_11 = __pyx_t_13;
    } else {
      __pyx_t_11 = __pyx_v_is_reverse;
    }
    if (!__pyx_t_11) {
      __pyx_t_13 = (!__pyx_v_is_reverse);
      if (__pyx_t_13) {
        __pyx_t_12 = (__pyx_v_tlen < 0);
        __pyx_t_14 = __pyx_t_12;
      } else {
        __pyx_t_14 = __pyx_t_13;
      }
      __pyx_t_13 = __pyx_t_14;
    } else {
      __pyx_t_13 = __pyx_t_11;
    }
    if (__pyx_t_13) {

      /* "pysamstats.pyx":368
 *             reads_mate_same_strand_fwd += 1
 *         elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 *             reads_faceaway += 1             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_faceaway_rev += 1
 */
      __pyx_v_reads_faceaway = (__pyx_v_reads_faceaway + 1);

      /* "pysamstats.pyx":369
 *         elif (is_reverse and tlen > 0) or (not is_reverse and tlen < 0):
 *             reads_faceaway += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_faceaway_rev += 1
 *             else:
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":370
 *             reads_faceaway += 1
 *             if is_reverse:
 *                 reads_faceaway_rev += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_faceaway_fwd += 1
 */
        __pyx_v_reads_faceaway_rev = (__pyx_v_reads_faceaway_rev + 1);
        goto __pyx_L11;
      }
      /*else*/ {

        /* "pysamstats.pyx":372
 *                 reads_faceaway_rev += 1
 *             else:
 *                 reads_faceaway_fwd += 1             # <<<<<<<<<<<<<<
 *         if is_softclipped(aln):
 *             reads_softclipped += 1
 */
        __pyx_v_reads_faceaway_fwd = (__pyx_v_reads_faceaway_fwd + 1);
      }
      __pyx_L11:;
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "pysamstats.pyx":373
 *             else:
 *                 reads_faceaway_fwd += 1
 *         if is_softclipped(aln):             # <<<<<<<<<<<<<<
 *             reads_softclipped += 1
 *             if is_reverse:
 */
    __pyx_t_13 = __pyx_f_10pysamstats_is_softclipped(__pyx_v_aln);
    if (__pyx_t_13) {

      /* "pysamstats.pyx":374
 *                 reads_faceaway_fwd += 1
 *         if is_softclipped(aln):
 *             reads_softclipped += 1             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_softclipped_rev += 1
 */
      __pyx_v_reads_softclipped = (__pyx_v_reads_softclipped + 1);

      /* "pysamstats.pyx":375
 *         if is_softclipped(aln):
 *             reads_softclipped += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_softclipped_rev += 1
 *             else:
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":376
 *             reads_softclipped += 1
 *             if is_reverse:
 *                 reads_softclipped_rev += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_softclipped_fwd += 1
 */
        __pyx_v_reads_softclipped_rev = (__pyx_v_reads_softclipped_rev + 1);
        goto __pyx_L13;
      }
      /*else*/ {

        /* "pysamstats.pyx":378
 *                 reads_softclipped_rev += 1
 *             else:
 *                 reads_softclipped_fwd += 1             # <<<<<<<<<<<<<<
 *         if is_duplicate:
 *             reads_duplicate += 1
 */
        __pyx_v_reads_softclipped_fwd = (__pyx_v_reads_softclipped_fwd + 1);
      }
      __pyx_L13:;
      goto __pyx_L12;
    }
    __pyx_L12:;

    /* "pysamstats.pyx":379
 *             else:
 *                 reads_softclipped_fwd += 1
 *         if is_duplicate:             # <<<<<<<<<<<<<<
 *             reads_duplicate += 1
 *             if is_reverse:
 */
    if (__pyx_v_is_duplicate) {

      /* "pysamstats.pyx":380
 *                 reads_softclipped_fwd += 1
 *         if is_duplicate:
 *             reads_duplicate += 1             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_duplicate_rev += 1
 */
      __pyx_v_reads_duplicate = (__pyx_v_reads_duplicate + 1);

      /* "pysamstats.pyx":381
 *         if is_duplicate:
 *             reads_duplicate += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_duplicate_rev += 1
 *             else:
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":382
 *             reads_duplicate += 1
 *             if is_reverse:
 *                 reads_duplicate_rev += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_duplicate_fwd += 1
 */
        __pyx_v_reads_duplicate_rev = (__pyx_v_reads_duplicate_rev + 1);
        goto __pyx_L15;
      }
      /*else*/ {

        /* "pysamstats.pyx":384
 *                 reads_duplicate_rev += 1
 *             else:
 *                 reads_duplicate_fwd += 1             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom, 'pos': pos,
 */
        __pyx_v_reads_duplicate_fwd = (__pyx_v_reads_duplicate_fwd + 1);
      }
      __pyx_L15:;
      goto __pyx_L14;
    }
    __pyx_L14:;
  }

  /* "pysamstats.pyx":386
 *                 reads_duplicate_fwd += 1
 * 
 *     return {'chrom': chrom, 'pos': pos,             # <<<<<<<<<<<<<<
 *            'reads_all': n,
 *            'reads_fwd': reads_fwd,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":387
 * 
 *     return {'chrom': chrom, 'pos': pos,
 *            'reads_all': n,             # <<<<<<<<<<<<<<
 *            'reads_fwd': reads_fwd,
 *            'reads_rev': reads_rev,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_all), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":388
 *     return {'chrom': chrom, 'pos': pos,
 *            'reads_all': n,
 *            'reads_fwd': reads_fwd,             # <<<<<<<<<<<<<<
 *            'reads_rev': reads_rev,
 *            'reads_pp': reads_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 388; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":389
 *            'reads_all': n,
 *            'reads_fwd': reads_fwd,
 *            'reads_rev': reads_rev,             # <<<<<<<<<<<<<<
 *            'reads_pp': reads_pp,
 *            'reads_pp_fwd': reads_pp_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":390
 *            'reads_fwd': reads_fwd,
 *            'reads_rev': reads_rev,
 *            'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *            'reads_pp_fwd': reads_pp_fwd,
 *            'reads_pp_rev': reads_pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":391
 *            'reads_rev': reads_rev,
 *            'reads_pp': reads_pp,
 *            'reads_pp_fwd': reads_pp_fwd,             # <<<<<<<<<<<<<<
 *            'reads_pp_rev': reads_pp_rev,
 *            'reads_mate_unmapped': reads_mate_unmapped,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 391; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":392
 *            'reads_pp': reads_pp,
 *            'reads_pp_fwd': reads_pp_fwd,
 *            'reads_pp_rev': reads_pp_rev,             # <<<<<<<<<<<<<<
 *            'reads_mate_unmapped': reads_mate_unmapped,
 *            'reads_mate_unmapped_fwd': reads_mate_unmapped_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 392; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":393
 *            'reads_pp_fwd': reads_pp_fwd,
 *            'reads_pp_rev': reads_pp_rev,
 *            'reads_mate_unmapped': reads_mate_unmapped,             # <<<<<<<<<<<<<<
 *            'reads_mate_unmapped_fwd': reads_mate_unmapped_fwd,
 *            'reads_mate_unmapped_rev': reads_mate_unmapped_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_unmapped); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_mate_unmapped), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":394
 *            'reads_pp_rev': reads_pp_rev,
 *            'reads_mate_unmapped': reads_mate_unmapped,
 *            'reads_mate_unmapped_fwd': reads_mate_unmapped_fwd,             # <<<<<<<<<<<<<<
 *            'reads_mate_unmapped_rev': reads_mate_unmapped_rev,
 *            'reads_mate_other_chr': reads_mate_other_chr,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_unmapped_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 394; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_10), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":395
 *            'reads_mate_unmapped': reads_mate_unmapped,
 *            'reads_mate_unmapped_fwd': reads_mate_unmapped_fwd,
 *            'reads_mate_unmapped_rev': reads_mate_unmapped_rev,             # <<<<<<<<<<<<<<
 *            'reads_mate_other_chr': reads_mate_other_chr,
 *            'reads_mate_other_chr_fwd': reads_mate_other_chr_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_unmapped_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_11), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":396
 *            'reads_mate_unmapped_fwd': reads_mate_unmapped_fwd,
 *            'reads_mate_unmapped_rev': reads_mate_unmapped_rev,
 *            'reads_mate_other_chr': reads_mate_other_chr,             # <<<<<<<<<<<<<<
 *            'reads_mate_other_chr_fwd': reads_mate_other_chr_fwd,
 *            'reads_mate_other_chr_rev': reads_mate_other_chr_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_other_chr); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 396; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_6), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":397
 *            'reads_mate_unmapped_rev': reads_mate_unmapped_rev,
 *            'reads_mate_other_chr': reads_mate_other_chr,
 *            'reads_mate_other_chr_fwd': reads_mate_other_chr_fwd,             # <<<<<<<<<<<<<<
 *            'reads_mate_other_chr_rev': reads_mate_other_chr_rev,
 *            'reads_mate_same_strand': reads_mate_same_strand,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_other_chr_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_12), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":398
 *            'reads_mate_other_chr': reads_mate_other_chr,
 *            'reads_mate_other_chr_fwd': reads_mate_other_chr_fwd,
 *            'reads_mate_other_chr_rev': reads_mate_other_chr_rev,             # <<<<<<<<<<<<<<
 *            'reads_mate_same_strand': reads_mate_same_strand,
 *            'reads_mate_same_strand_fwd': reads_mate_same_strand_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_other_chr_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 398; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_13), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":399
 *            'reads_mate_other_chr_fwd': reads_mate_other_chr_fwd,
 *            'reads_mate_other_chr_rev': reads_mate_other_chr_rev,
 *            'reads_mate_same_strand': reads_mate_same_strand,             # <<<<<<<<<<<<<<
 *            'reads_mate_same_strand_fwd': reads_mate_same_strand_fwd,
 *            'reads_mate_same_strand_rev': reads_mate_same_strand_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_same_strand); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 399; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_7), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":400
 *            'reads_mate_other_chr_rev': reads_mate_other_chr_rev,
 *            'reads_mate_same_strand': reads_mate_same_strand,
 *            'reads_mate_same_strand_fwd': reads_mate_same_strand_fwd,             # <<<<<<<<<<<<<<
 *            'reads_mate_same_strand_rev': reads_mate_same_strand_rev,
 *            'reads_faceaway': reads_faceaway,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_same_strand_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_14), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":401
 *            'reads_mate_same_strand': reads_mate_same_strand,
 *            'reads_mate_same_strand_fwd': reads_mate_same_strand_fwd,
 *            'reads_mate_same_strand_rev': reads_mate_same_strand_rev,             # <<<<<<<<<<<<<<
 *            'reads_faceaway': reads_faceaway,
 *            'reads_faceaway_fwd': reads_faceaway_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mate_same_strand_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 401; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_15), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":402
 *            'reads_mate_same_strand_fwd': reads_mate_same_strand_fwd,
 *            'reads_mate_same_strand_rev': reads_mate_same_strand_rev,
 *            'reads_faceaway': reads_faceaway,             # <<<<<<<<<<<<<<
 *            'reads_faceaway_fwd': reads_faceaway_fwd,
 *            'reads_faceaway_rev': reads_faceaway_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_faceaway); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 402; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_faceaway), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":403
 *            'reads_mate_same_strand_rev': reads_mate_same_strand_rev,
 *            'reads_faceaway': reads_faceaway,
 *            'reads_faceaway_fwd': reads_faceaway_fwd,             # <<<<<<<<<<<<<<
 *            'reads_faceaway_rev': reads_faceaway_rev,
 *            'reads_softclipped': reads_softclipped,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_faceaway_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 403; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_faceaway_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":404
 *            'reads_faceaway': reads_faceaway,
 *            'reads_faceaway_fwd': reads_faceaway_fwd,
 *            'reads_faceaway_rev': reads_faceaway_rev,             # <<<<<<<<<<<<<<
 *            'reads_softclipped': reads_softclipped,
 *            'reads_softclipped_fwd': reads_softclipped_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_faceaway_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 404; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_faceaway_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":405
 *            'reads_faceaway_fwd': reads_faceaway_fwd,
 *            'reads_faceaway_rev': reads_faceaway_rev,
 *            'reads_softclipped': reads_softclipped,             # <<<<<<<<<<<<<<
 *            'reads_softclipped_fwd': reads_softclipped_fwd,
 *            'reads_softclipped_rev': reads_softclipped_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_softclipped); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_softclipped), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":406
 *            'reads_faceaway_rev': reads_faceaway_rev,
 *            'reads_softclipped': reads_softclipped,
 *            'reads_softclipped_fwd': reads_softclipped_fwd,             # <<<<<<<<<<<<<<
 *            'reads_softclipped_rev': reads_softclipped_rev,
 *            'reads_duplicate': reads_duplicate,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_softclipped_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_16), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":407
 *            'reads_softclipped': reads_softclipped,
 *            'reads_softclipped_fwd': reads_softclipped_fwd,
 *            'reads_softclipped_rev': reads_softclipped_rev,             # <<<<<<<<<<<<<<
 *            'reads_duplicate': reads_duplicate,
 *            'reads_duplicate_fwd': reads_duplicate_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_softclipped_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 407; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s_17), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":408
 *            'reads_softclipped_fwd': reads_softclipped_fwd,
 *            'reads_softclipped_rev': reads_softclipped_rev,
 *            'reads_duplicate': reads_duplicate,             # <<<<<<<<<<<<<<
 *            'reads_duplicate_fwd': reads_duplicate_fwd,
 *            'reads_duplicate_rev': reads_duplicate_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_duplicate); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_duplicate), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":409
 *            'reads_softclipped_rev': reads_softclipped_rev,
 *            'reads_duplicate': reads_duplicate,
 *            'reads_duplicate_fwd': reads_duplicate_fwd,             # <<<<<<<<<<<<<<
 *            'reads_duplicate_rev': reads_duplicate_rev,
 *            }
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_duplicate_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_duplicate_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":410
 *            'reads_duplicate': reads_duplicate,
 *            'reads_duplicate_fwd': reads_duplicate_fwd,
 *            'reads_duplicate_rev': reads_duplicate_rev,             # <<<<<<<<<<<<<<
 *            }
 * 
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_duplicate_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_duplicate_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 386; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_22construct_rec_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_22construct_rec_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_coverage_ext_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__col,&__pyx_n_s__one_based,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__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_coverage_ext_strand", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_coverage_ext_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[1]);
    if (values[2]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":280
 * 
 * 
 * cpdef object construct_rec_coverage_ext_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_coverage_ext_strand", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_21construct_rec_coverage_ext_strand(__pyx_self, __pyx_v_samfile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_21construct_rec_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_coverage_ext_strand", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_coverage_ext_strand(__pyx_v_samfile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 280; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_coverage_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_25generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_24stat_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_24stat_coverage_ext_strand = {__Pyx_NAMESTR("stat_coverage_ext_strand"), (PyCFunction)__pyx_pw_10pysamstats_24stat_coverage_ext_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_24stat_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_coverage_ext_strand (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__samfile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysamstats.pyx":414
 * 
 * 
 * def stat_coverage_ext_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_18;
    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__chrom);
          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__one_based);
          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, "stat_coverage_ext_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
    __pyx_v_one_based = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_ext_strand", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_coverage_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_23stat_coverage_ext_strand(__pyx_self, __pyx_v_samfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_23stat_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_coverage_ext_strand", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *)__pyx_ptype_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_25generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_coverage_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_25generator3(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_coverage_ext_strand __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":415
 * 
 * def stat_coverage_ext_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(chrom, start, end):
 *         yield construct_rec_coverage_ext_strand(samfile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":416
 * def stat_coverage_ext_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_coverage_ext_strand(samfile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 416; __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 = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 416; __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 = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":417
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 *         yield construct_rec_coverage_ext_strand(samfile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_coverage_ext_strand(__pyx_cur_scope->__pyx_v_samfile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_coverage_ext_strand", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_27write_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_27write_coverage_ext_strand = {__Pyx_NAMESTR("write_coverage_ext_strand"), (PyCFunction)__pyx_pw_10pysamstats_27write_coverage_ext_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_27write_coverage_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_coverage_ext_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_coverage_ext_strand", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_26write_coverage_ext_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":420
 * 
 * 
 * def write_coverage_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all',
 */

static PyObject *__pyx_pf_10pysamstats_26write_coverage_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_coverage_ext_strand", 0);

  /* "pysamstats.pyx":421
 * 
 * def write_coverage_ext_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *                   'reads_all',
 *                   'reads_fwd',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_19));
  __pyx_v_fieldnames = __pyx_k_tuple_19;

  /* "pysamstats.pyx":447
 *                   'reads_duplicate_rev',
 *                   )
 *     write_stats(stat_coverage_ext_strand, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s_20); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 447; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_coverage_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":455
 * 
 * 
 * cpdef object construct_rec_variation(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                      PileupProxy col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_29construct_rec_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_variation(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_variation *__pyx_optional_args) {

  /* "pysamstats.pyx":456
 * 
 * cpdef object construct_rec_variation(Samfile samfile, Fastafile fafile,
 *                                      PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  unsigned int __pyx_v_reads_pp;
  unsigned int __pyx_v_matches;
  unsigned int __pyx_v_matches_pp;
  unsigned int __pyx_v_mismatches;
  unsigned int __pyx_v_mismatches_pp;
  unsigned int __pyx_v_deletions;
  unsigned int __pyx_v_deletions_pp;
  unsigned int __pyx_v_insertions;
  unsigned int __pyx_v_insertions_pp;
  unsigned int __pyx_v_A;
  unsigned int __pyx_v_A_pp;
  unsigned int __pyx_v_C;
  unsigned int __pyx_v_C_pp;
  unsigned int __pyx_v_T;
  unsigned int __pyx_v_T_pp;
  unsigned int __pyx_v_G;
  unsigned int __pyx_v_G_pp;
  unsigned int __pyx_v_N;
  unsigned int __pyx_v_N_pp;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_v_refbase = NULL;
  PyObject *__pyx_v_alnbase = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_variation", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":467
 *     cdef bint is_proper_pair
 *     # counting variables
 *     cdef unsigned int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int matches = 0
 *     cdef unsigned int matches_pp = 0
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":468
 *     # counting variables
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int matches = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int matches_pp = 0
 *     cdef unsigned int mismatches = 0
 */
  __pyx_v_matches = 0;

  /* "pysamstats.pyx":469
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int matches = 0
 *     cdef unsigned int matches_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int mismatches = 0
 *     cdef unsigned int mismatches_pp = 0
 */
  __pyx_v_matches_pp = 0;

  /* "pysamstats.pyx":470
 *     cdef unsigned int matches = 0
 *     cdef unsigned int matches_pp = 0
 *     cdef unsigned int mismatches = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int mismatches_pp = 0
 *     cdef unsigned int deletions = 0
 */
  __pyx_v_mismatches = 0;

  /* "pysamstats.pyx":471
 *     cdef unsigned int matches_pp = 0
 *     cdef unsigned int mismatches = 0
 *     cdef unsigned int mismatches_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int deletions = 0
 *     cdef unsigned int deletions_pp = 0
 */
  __pyx_v_mismatches_pp = 0;

  /* "pysamstats.pyx":472
 *     cdef unsigned int mismatches = 0
 *     cdef unsigned int mismatches_pp = 0
 *     cdef unsigned int deletions = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int deletions_pp = 0
 *     cdef unsigned int insertions = 0
 */
  __pyx_v_deletions = 0;

  /* "pysamstats.pyx":473
 *     cdef unsigned int mismatches_pp = 0
 *     cdef unsigned int deletions = 0
 *     cdef unsigned int deletions_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int insertions = 0
 *     cdef unsigned int insertions_pp = 0
 */
  __pyx_v_deletions_pp = 0;

  /* "pysamstats.pyx":474
 *     cdef unsigned int deletions = 0
 *     cdef unsigned int deletions_pp = 0
 *     cdef unsigned int insertions = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int insertions_pp = 0
 *     cdef unsigned int A = 0
 */
  __pyx_v_insertions = 0;

  /* "pysamstats.pyx":475
 *     cdef unsigned int deletions_pp = 0
 *     cdef unsigned int insertions = 0
 *     cdef unsigned int insertions_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int A = 0
 *     cdef unsigned int A_pp = 0
 */
  __pyx_v_insertions_pp = 0;

  /* "pysamstats.pyx":476
 *     cdef unsigned int insertions = 0
 *     cdef unsigned int insertions_pp = 0
 *     cdef unsigned int A = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int A_pp = 0
 *     cdef unsigned int C = 0
 */
  __pyx_v_A = 0;

  /* "pysamstats.pyx":477
 *     cdef unsigned int insertions_pp = 0
 *     cdef unsigned int A = 0
 *     cdef unsigned int A_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int C = 0
 *     cdef unsigned int C_pp = 0
 */
  __pyx_v_A_pp = 0;

  /* "pysamstats.pyx":478
 *     cdef unsigned int A = 0
 *     cdef unsigned int A_pp = 0
 *     cdef unsigned int C = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int C_pp = 0
 *     cdef unsigned int T = 0
 */
  __pyx_v_C = 0;

  /* "pysamstats.pyx":479
 *     cdef unsigned int A_pp = 0
 *     cdef unsigned int C = 0
 *     cdef unsigned int C_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int T = 0
 *     cdef unsigned int T_pp = 0
 */
  __pyx_v_C_pp = 0;

  /* "pysamstats.pyx":480
 *     cdef unsigned int C = 0
 *     cdef unsigned int C_pp = 0
 *     cdef unsigned int T = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int T_pp = 0
 *     cdef unsigned int G = 0
 */
  __pyx_v_T = 0;

  /* "pysamstats.pyx":481
 *     cdef unsigned int C_pp = 0
 *     cdef unsigned int T = 0
 *     cdef unsigned int T_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int G = 0
 *     cdef unsigned int G_pp = 0
 */
  __pyx_v_T_pp = 0;

  /* "pysamstats.pyx":482
 *     cdef unsigned int T = 0
 *     cdef unsigned int T_pp = 0
 *     cdef unsigned int G = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int G_pp = 0
 *     cdef unsigned int N = 0
 */
  __pyx_v_G = 0;

  /* "pysamstats.pyx":483
 *     cdef unsigned int T_pp = 0
 *     cdef unsigned int G = 0
 *     cdef unsigned int G_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int N = 0
 *     cdef unsigned int N_pp = 0
 */
  __pyx_v_G_pp = 0;

  /* "pysamstats.pyx":484
 *     cdef unsigned int G = 0
 *     cdef unsigned int G_pp = 0
 *     cdef unsigned int N = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int N_pp = 0
 * 
 */
  __pyx_v_N = 0;

  /* "pysamstats.pyx":485
 *     cdef unsigned int G_pp = 0
 *     cdef unsigned int N = 0
 *     cdef unsigned int N_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_N_pp = 0;

  /* "pysamstats.pyx":488
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 488; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":489
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":492
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":493
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # reference base
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":496
 * 
 *     # reference base
 *     refbase = fafile.fetch(reference=chrom, start=col.pos, end=col.pos+1).upper()             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_fafile), __pyx_n_s__fetch); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__reference), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = PyInt_FromLong(__pyx_v_col->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__start), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyInt_FromLong((__pyx_v_col->pos + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__end), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__upper); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 496; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":499
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         # read.qpos
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":500
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         # read.qpos
 *         # read.is_del
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":504
 *         # read.is_del
 *         # read.indel
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":505
 *         # read.indel
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":506
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         if is_proper_pair:
 *             reads_pp += 1
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":507
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *         if read.is_del:
 */
    if (__pyx_v_is_proper_pair) {

      /* "pysamstats.pyx":508
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         if is_proper_pair:
 *             reads_pp += 1             # <<<<<<<<<<<<<<
 *         if read.is_del:
 *             deletions += 1
 */
      __pyx_v_reads_pp = (__pyx_v_reads_pp + 1);
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "pysamstats.pyx":509
 *         if is_proper_pair:
 *             reads_pp += 1
 *         if read.is_del:             # <<<<<<<<<<<<<<
 *             deletions += 1
 *             if is_proper_pair:
 */
    if (__pyx_v_read->is_del) {

      /* "pysamstats.pyx":510
 *             reads_pp += 1
 *         if read.is_del:
 *             deletions += 1             # <<<<<<<<<<<<<<
 *             if is_proper_pair:
 *                 deletions_pp += 1
 */
      __pyx_v_deletions = (__pyx_v_deletions + 1);

      /* "pysamstats.pyx":511
 *         if read.is_del:
 *             deletions += 1
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 deletions_pp += 1
 *         else:
 */
      if (__pyx_v_is_proper_pair) {

        /* "pysamstats.pyx":512
 *             deletions += 1
 *             if is_proper_pair:
 *                 deletions_pp += 1             # <<<<<<<<<<<<<<
 *         else:
 * #            alnbase = get_seq_range(aln, 0, aln.core.l_qseq)[read.qpos]
 */
        __pyx_v_deletions_pp = (__pyx_v_deletions_pp + 1);
        goto __pyx_L7;
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    /*else*/ {

      /* "pysamstats.pyx":515
 *         else:
 * #            alnbase = get_seq_range(aln, 0, aln.core.l_qseq)[read.qpos]
 *             alnbase = get_seq_base(aln, read.qpos)             # <<<<<<<<<<<<<<
 * #            print refbase, alnbase
 *             if alnbase == 'A':
 */
      __pyx_t_1 = __pyx_f_10pysamstats_get_seq_base(__pyx_v_aln, __pyx_v_read->qpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 515; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_v_alnbase);
      __pyx_v_alnbase = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "pysamstats.pyx":517
 *             alnbase = get_seq_base(aln, read.qpos)
 * #            print refbase, alnbase
 *             if alnbase == 'A':             # <<<<<<<<<<<<<<
 *                 A += 1
 *                 if is_proper_pair:
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, ((PyObject *)__pyx_n_s__A), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 517; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":518
 * #            print refbase, alnbase
 *             if alnbase == 'A':
 *                 A += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     A_pp += 1
 */
        __pyx_v_A = (__pyx_v_A + 1);

        /* "pysamstats.pyx":519
 *             if alnbase == 'A':
 *                 A += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     A_pp += 1
 *             elif alnbase == 'T':
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":520
 *                 A += 1
 *                 if is_proper_pair:
 *                     A_pp += 1             # <<<<<<<<<<<<<<
 *             elif alnbase == 'T':
 *                 T += 1
 */
          __pyx_v_A_pp = (__pyx_v_A_pp + 1);
          goto __pyx_L9;
        }
        __pyx_L9:;
        goto __pyx_L8;
      }

      /* "pysamstats.pyx":521
 *                 if is_proper_pair:
 *                     A_pp += 1
 *             elif alnbase == 'T':             # <<<<<<<<<<<<<<
 *                 T += 1
 *                 if is_proper_pair:
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, ((PyObject *)__pyx_n_s__T), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":522
 *                     A_pp += 1
 *             elif alnbase == 'T':
 *                 T += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     T_pp += 1
 */
        __pyx_v_T = (__pyx_v_T + 1);

        /* "pysamstats.pyx":523
 *             elif alnbase == 'T':
 *                 T += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     T_pp += 1
 *             elif alnbase == 'C':
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":524
 *                 T += 1
 *                 if is_proper_pair:
 *                     T_pp += 1             # <<<<<<<<<<<<<<
 *             elif alnbase == 'C':
 *                 C += 1
 */
          __pyx_v_T_pp = (__pyx_v_T_pp + 1);
          goto __pyx_L10;
        }
        __pyx_L10:;
        goto __pyx_L8;
      }

      /* "pysamstats.pyx":525
 *                 if is_proper_pair:
 *                     T_pp += 1
 *             elif alnbase == 'C':             # <<<<<<<<<<<<<<
 *                 C += 1
 *                 if is_proper_pair:
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, ((PyObject *)__pyx_n_s__C), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 525; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":526
 *                     T_pp += 1
 *             elif alnbase == 'C':
 *                 C += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     C_pp += 1
 */
        __pyx_v_C = (__pyx_v_C + 1);

        /* "pysamstats.pyx":527
 *             elif alnbase == 'C':
 *                 C += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     C_pp += 1
 *             elif alnbase == 'G':
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":528
 *                 C += 1
 *                 if is_proper_pair:
 *                     C_pp += 1             # <<<<<<<<<<<<<<
 *             elif alnbase == 'G':
 *                 G += 1
 */
          __pyx_v_C_pp = (__pyx_v_C_pp + 1);
          goto __pyx_L11;
        }
        __pyx_L11:;
        goto __pyx_L8;
      }

      /* "pysamstats.pyx":529
 *                 if is_proper_pair:
 *                     C_pp += 1
 *             elif alnbase == 'G':             # <<<<<<<<<<<<<<
 *                 G += 1
 *                 if is_proper_pair:
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, ((PyObject *)__pyx_n_s__G), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 529; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":530
 *                     C_pp += 1
 *             elif alnbase == 'G':
 *                 G += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     G_pp += 1
 */
        __pyx_v_G = (__pyx_v_G + 1);

        /* "pysamstats.pyx":531
 *             elif alnbase == 'G':
 *                 G += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     G_pp += 1
 *             elif alnbase == 'N':
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":532
 *                 G += 1
 *                 if is_proper_pair:
 *                     G_pp += 1             # <<<<<<<<<<<<<<
 *             elif alnbase == 'N':
 *                 N += 1
 */
          __pyx_v_G_pp = (__pyx_v_G_pp + 1);
          goto __pyx_L12;
        }
        __pyx_L12:;
        goto __pyx_L8;
      }

      /* "pysamstats.pyx":533
 *                 if is_proper_pair:
 *                     G_pp += 1
 *             elif alnbase == 'N':             # <<<<<<<<<<<<<<
 *                 N += 1
 *                 if is_proper_pair:
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, ((PyObject *)__pyx_n_s__N), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 533; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":534
 *                     G_pp += 1
 *             elif alnbase == 'N':
 *                 N += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     N_pp += 1
 */
        __pyx_v_N = (__pyx_v_N + 1);

        /* "pysamstats.pyx":535
 *             elif alnbase == 'N':
 *                 N += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     N_pp += 1
 *             if read.indel > 0:
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":536
 *                 N += 1
 *                 if is_proper_pair:
 *                     N_pp += 1             # <<<<<<<<<<<<<<
 *             if read.indel > 0:
 *                 insertions += 1
 */
          __pyx_v_N_pp = (__pyx_v_N_pp + 1);
          goto __pyx_L13;
        }
        __pyx_L13:;
        goto __pyx_L8;
      }
      __pyx_L8:;

      /* "pysamstats.pyx":537
 *                 if is_proper_pair:
 *                     N_pp += 1
 *             if read.indel > 0:             # <<<<<<<<<<<<<<
 *                 insertions += 1
 *                 if is_proper_pair:
 */
      __pyx_t_10 = (__pyx_v_read->indel > 0);
      if (__pyx_t_10) {

        /* "pysamstats.pyx":538
 *                     N_pp += 1
 *             if read.indel > 0:
 *                 insertions += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     insertions_pp += 1
 */
        __pyx_v_insertions = (__pyx_v_insertions + 1);

        /* "pysamstats.pyx":539
 *             if read.indel > 0:
 *                 insertions += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     insertions_pp += 1
 *             if alnbase == refbase:
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":540
 *                 insertions += 1
 *                 if is_proper_pair:
 *                     insertions_pp += 1             # <<<<<<<<<<<<<<
 *             if alnbase == refbase:
 *                 matches += 1
 */
          __pyx_v_insertions_pp = (__pyx_v_insertions_pp + 1);
          goto __pyx_L15;
        }
        __pyx_L15:;
        goto __pyx_L14;
      }
      __pyx_L14:;

      /* "pysamstats.pyx":541
 *                 if is_proper_pair:
 *                     insertions_pp += 1
 *             if alnbase == refbase:             # <<<<<<<<<<<<<<
 *                 matches += 1
 *                 if is_proper_pair:
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, __pyx_v_refbase, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":542
 *                     insertions_pp += 1
 *             if alnbase == refbase:
 *                 matches += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     matches_pp += 1
 */
        __pyx_v_matches = (__pyx_v_matches + 1);

        /* "pysamstats.pyx":543
 *             if alnbase == refbase:
 *                 matches += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     matches_pp += 1
 *             else:
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":544
 *                 matches += 1
 *                 if is_proper_pair:
 *                     matches_pp += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 mismatches += 1
 */
          __pyx_v_matches_pp = (__pyx_v_matches_pp + 1);
          goto __pyx_L17;
        }
        __pyx_L17:;
        goto __pyx_L16;
      }
      /*else*/ {

        /* "pysamstats.pyx":546
 *                     matches_pp += 1
 *             else:
 *                 mismatches += 1             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     mismatches_pp += 1
 */
        __pyx_v_mismatches = (__pyx_v_mismatches + 1);

        /* "pysamstats.pyx":547
 *             else:
 *                 mismatches += 1
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     mismatches_pp += 1
 * 
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":548
 *                 mismatches += 1
 *                 if is_proper_pair:
 *                     mismatches_pp += 1             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
          __pyx_v_mismatches_pp = (__pyx_v_mismatches_pp + 1);
          goto __pyx_L18;
        }
        __pyx_L18:;
      }
      __pyx_L16:;
    }
    __pyx_L6:;
  }

  /* "pysamstats.pyx":550
 *                     mismatches_pp += 1
 * 
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,             # <<<<<<<<<<<<<<
 *             'reads_all': n, 'reads_pp': reads_pp,
 *             'matches': matches,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__ref), __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":551
 * 
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 *             'reads_all': n, 'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *             'matches': matches,
 *             'matches_pp': matches_pp,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reads_all), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 551; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reads_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":552
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 *             'reads_all': n, 'reads_pp': reads_pp,
 *             'matches': matches,             # <<<<<<<<<<<<<<
 *             'matches_pp': matches_pp,
 *             'mismatches': mismatches,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_matches); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 552; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__matches), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":553
 *             'reads_all': n, 'reads_pp': reads_pp,
 *             'matches': matches,
 *             'matches_pp': matches_pp,             # <<<<<<<<<<<<<<
 *             'mismatches': mismatches,
 *             'mismatches_pp': mismatches_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_matches_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 553; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__matches_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":554
 *             'matches': matches,
 *             'matches_pp': matches_pp,
 *             'mismatches': mismatches,             # <<<<<<<<<<<<<<
 *             'mismatches_pp': mismatches_pp,
 *             'deletions': deletions,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_mismatches); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 554; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mismatches), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":555
 *             'matches_pp': matches_pp,
 *             'mismatches': mismatches,
 *             'mismatches_pp': mismatches_pp,             # <<<<<<<<<<<<<<
 *             'deletions': deletions,
 *             'deletions_pp': deletions_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_mismatches_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mismatches_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":556
 *             'mismatches': mismatches,
 *             'mismatches_pp': mismatches_pp,
 *             'deletions': deletions,             # <<<<<<<<<<<<<<
 *             'deletions_pp': deletions_pp,
 *             'insertions': insertions,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_deletions); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__deletions), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":557
 *             'mismatches_pp': mismatches_pp,
 *             'deletions': deletions,
 *             'deletions_pp': deletions_pp,             # <<<<<<<<<<<<<<
 *             'insertions': insertions,
 *             'insertions_pp': insertions_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_deletions_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__deletions_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":558
 *             'deletions': deletions,
 *             'deletions_pp': deletions_pp,
 *             'insertions': insertions,             # <<<<<<<<<<<<<<
 *             'insertions_pp': insertions_pp,
 *             'A': A, 'A_pp': A_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_insertions); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__insertions), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":559
 *             'deletions_pp': deletions_pp,
 *             'insertions': insertions,
 *             'insertions_pp': insertions_pp,             # <<<<<<<<<<<<<<
 *             'A': A, 'A_pp': A_pp,
 *             'C': C, 'C_pp': C_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_insertions_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__insertions_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":560
 *             'insertions': insertions,
 *             'insertions_pp': insertions_pp,
 *             'A': A, 'A_pp': A_pp,             # <<<<<<<<<<<<<<
 *             'C': C, 'C_pp': C_pp,
 *             'T': T, 'T_pp': T_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_A); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__A), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_A_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__A_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":561
 *             'insertions_pp': insertions_pp,
 *             'A': A, 'A_pp': A_pp,
 *             'C': C, 'C_pp': C_pp,             # <<<<<<<<<<<<<<
 *             'T': T, 'T_pp': T_pp,
 *             'G': G, 'G_pp': G_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_C); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__C), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_C_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 561; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__C_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":562
 *             'A': A, 'A_pp': A_pp,
 *             'C': C, 'C_pp': C_pp,
 *             'T': T, 'T_pp': T_pp,             # <<<<<<<<<<<<<<
 *             'G': G, 'G_pp': G_pp,
 *             'N': N, 'N_pp': N_pp}
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_T); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__T), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_T_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__T_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":563
 *             'C': C, 'C_pp': C_pp,
 *             'T': T, 'T_pp': T_pp,
 *             'G': G, 'G_pp': G_pp,             # <<<<<<<<<<<<<<
 *             'N': N, 'N_pp': N_pp}
 * 
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_G); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__G), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_G_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__G_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":564
 *             'T': T, 'T_pp': T_pp,
 *             'G': G, 'G_pp': G_pp,
 *             'N': N, 'N_pp': N_pp}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_N); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__N), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_N_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 564; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__N_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 550; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_variation", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_refbase);
  __Pyx_XDECREF(__pyx_v_alnbase);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_29construct_rec_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_29construct_rec_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_variation (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__fafile,&__pyx_n_s__col,&__pyx_n_s__one_based,0};
    PyObject* values[4] = {0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_variation", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_variation", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_variation") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __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);
        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_9csamtools_Samfile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[2]);
    if (values[3]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":456
 * 
 * cpdef object construct_rec_variation(Samfile samfile, Fastafile fafile,
 *                                      PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_variation", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_variation", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_28construct_rec_variation(__pyx_self, __pyx_v_samfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":455
 * 
 * 
 * cpdef object construct_rec_variation(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                      PileupProxy col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pf_10pysamstats_28construct_rec_variation(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_variation __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_variation", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_variation(__pyx_v_samfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_variation", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_32generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_31stat_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_31stat_variation = {__Pyx_NAMESTR("stat_variation"), (PyCFunction)__pyx_pw_10pysamstats_31stat_variation, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_31stat_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_variation (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__samfile,&__pyx_n_s__fafile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "pysamstats.pyx":567
 * 
 * 
 * def stat_variation(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    values[5] = __pyx_k_21;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        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__fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stat_variation", 0, 2, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__chrom);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_variation") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)values[1]);
    __pyx_v_chrom = values[2];
    __pyx_v_start = values[3];
    __pyx_v_end = values[4];
    __pyx_v_one_based = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_variation", 0, 2, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_variation", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_30stat_variation(__pyx_self, __pyx_v_samfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_30stat_variation(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_variation", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *)__pyx_ptype_10pysamstats___pyx_scope_struct_4_stat_variation->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_4_stat_variation, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_fafile = __pyx_v_fafile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_32generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_variation", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_32generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_variation __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":568
 * 
 * def stat_variation(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_variation(samfile, fafile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 568; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":569
 * def stat_variation(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_variation(samfile, fafile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); 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_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 569; __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 = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 569; __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 = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":570
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_variation(samfile, fafile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_variation(__pyx_cur_scope->__pyx_v_samfile, __pyx_cur_scope->__pyx_v_fafile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 570; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_variation", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_34write_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_34write_variation = {__Pyx_NAMESTR("write_variation"), (PyCFunction)__pyx_pw_10pysamstats_34write_variation, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_34write_variation(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_variation (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_variation", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_33write_variation(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":573
 * 
 * 
 * def write_variation(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 *                   'reads_all', 'reads_pp',
 */

static PyObject *__pyx_pf_10pysamstats_33write_variation(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_variation", 0);

  /* "pysamstats.pyx":574
 * 
 * def write_variation(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'ref',             # <<<<<<<<<<<<<<
 *                   'reads_all', 'reads_pp',
 *                   'matches', 'matches_pp',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_22));
  __pyx_v_fieldnames = __pyx_k_tuple_22;

  /* "pysamstats.pyx":581
 *                   'insertions', 'insertions_pp',
 *                   'A', 'A_pp', 'C', 'C_pp', 'T', 'T_pp', 'G', 'G_pp', 'N', 'N_pp')
 *     write_stats(stat_variation, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_variation); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __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 = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_variation", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":593
 * 
 * 
 * cdef inline init_pp_strand(CountPpStrand* c):             # <<<<<<<<<<<<<<
 *     c.all = c.fwd = c.rev = c.pp = c.pp_fwd = c.pp_rev = 0
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_10pysamstats_init_pp_strand(struct __pyx_t_10pysamstats_CountPpStrand *__pyx_v_c) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("init_pp_strand", 0);

  /* "pysamstats.pyx":594
 * 
 * cdef inline init_pp_strand(CountPpStrand* c):
 *     c.all = c.fwd = c.rev = c.pp = c.pp_fwd = c.pp_rev = 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_v_c->all = 0;
  __pyx_v_c->fwd = 0;
  __pyx_v_c->rev = 0;
  __pyx_v_c->pp = 0;
  __pyx_v_c->pp_fwd = 0;
  __pyx_v_c->pp_rev = 0;

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

/* "pysamstats.pyx":597
 * 
 * 
 * cdef inline incr_pp_strand(CountPpStrand* c, bint is_reverse, bint is_proper_pair):             # <<<<<<<<<<<<<<
 *     c.all += 1
 *     if is_reverse:
 */

static CYTHON_INLINE PyObject *__pyx_f_10pysamstats_incr_pp_strand(struct __pyx_t_10pysamstats_CountPpStrand *__pyx_v_c, int __pyx_v_is_reverse, int __pyx_v_is_proper_pair) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("incr_pp_strand", 0);

  /* "pysamstats.pyx":598
 * 
 * cdef inline incr_pp_strand(CountPpStrand* c, bint is_reverse, bint is_proper_pair):
 *     c.all += 1             # <<<<<<<<<<<<<<
 *     if is_reverse:
 *         c.rev += 1
 */
  __pyx_v_c->all = (__pyx_v_c->all + 1);

  /* "pysamstats.pyx":599
 * cdef inline incr_pp_strand(CountPpStrand* c, bint is_reverse, bint is_proper_pair):
 *     c.all += 1
 *     if is_reverse:             # <<<<<<<<<<<<<<
 *         c.rev += 1
 *         if is_proper_pair:
 */
  if (__pyx_v_is_reverse) {

    /* "pysamstats.pyx":600
 *     c.all += 1
 *     if is_reverse:
 *         c.rev += 1             # <<<<<<<<<<<<<<
 *         if is_proper_pair:
 *             c.pp += 1
 */
    __pyx_v_c->rev = (__pyx_v_c->rev + 1);

    /* "pysamstats.pyx":601
 *     if is_reverse:
 *         c.rev += 1
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             c.pp += 1
 *             c.pp_rev += 1
 */
    if (__pyx_v_is_proper_pair) {

      /* "pysamstats.pyx":602
 *         c.rev += 1
 *         if is_proper_pair:
 *             c.pp += 1             # <<<<<<<<<<<<<<
 *             c.pp_rev += 1
 *     else:
 */
      __pyx_v_c->pp = (__pyx_v_c->pp + 1);

      /* "pysamstats.pyx":603
 *         if is_proper_pair:
 *             c.pp += 1
 *             c.pp_rev += 1             # <<<<<<<<<<<<<<
 *     else:
 *         c.fwd += 1
 */
      __pyx_v_c->pp_rev = (__pyx_v_c->pp_rev + 1);
      goto __pyx_L4;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysamstats.pyx":605
 *             c.pp_rev += 1
 *     else:
 *         c.fwd += 1             # <<<<<<<<<<<<<<
 *         if is_proper_pair:
 *             c.pp += 1
 */
    __pyx_v_c->fwd = (__pyx_v_c->fwd + 1);

    /* "pysamstats.pyx":606
 *     else:
 *         c.fwd += 1
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             c.pp += 1
 *             c.pp_fwd += 1
 */
    if (__pyx_v_is_proper_pair) {

      /* "pysamstats.pyx":607
 *         c.fwd += 1
 *         if is_proper_pair:
 *             c.pp += 1             # <<<<<<<<<<<<<<
 *             c.pp_fwd += 1
 * 
 */
      __pyx_v_c->pp = (__pyx_v_c->pp + 1);

      /* "pysamstats.pyx":608
 *         if is_proper_pair:
 *             c.pp += 1
 *             c.pp_fwd += 1             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_v_c->pp_fwd = (__pyx_v_c->pp_fwd + 1);
      goto __pyx_L5;
    }
    __pyx_L5:;
  }
  __pyx_L3:;

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

/* "pysamstats.pyx":611
 * 
 * 
 * cpdef object construct_rec_variation_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                             PileupProxy col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_36construct_rec_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_variation_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_variation_strand *__pyx_optional_args) {

  /* "pysamstats.pyx":612
 * 
 * cpdef object construct_rec_variation_strand(Samfile samfile, Fastafile fafile,
 *                                             PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_is_reverse;
  struct __pyx_t_10pysamstats_CountPpStrand __pyx_v_reads;
  struct __pyx_t_10pysamstats_CountPpStrand __pyx_v_matches;
  struct __pyx_t_10pysamstats_CountPpStrand __pyx_v_mismatches;
  struct __pyx_t_10pysamstats_CountPpStrand __pyx_v_deletions;
  struct __pyx_t_10pysamstats_CountPpStrand __pyx_v_insertions;
  struct __pyx_t_10pysamstats_CountPpStrand __pyx_v_A;
  struct __pyx_t_10pysamstats_CountPpStrand __pyx_v_C;
  struct __pyx_t_10pysamstats_CountPpStrand __pyx_v_T;
  struct __pyx_t_10pysamstats_CountPpStrand __pyx_v_G;
  struct __pyx_t_10pysamstats_CountPpStrand __pyx_v_N;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_v_refbase = NULL;
  PyObject *__pyx_v_alnbase = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_variation_strand", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":626
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 *     init_pp_strand(&reads)
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 626; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":627
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 *     init_pp_strand(&reads)
 *     init_pp_strand(&matches)
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":628
 *     n = col.n
 *     plp = col.plp
 *     init_pp_strand(&reads)             # <<<<<<<<<<<<<<
 *     init_pp_strand(&matches)
 *     init_pp_strand(&mismatches)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_init_pp_strand((&__pyx_v_reads)); 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_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":629
 *     plp = col.plp
 *     init_pp_strand(&reads)
 *     init_pp_strand(&matches)             # <<<<<<<<<<<<<<
 *     init_pp_strand(&mismatches)
 *     init_pp_strand(&deletions)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_init_pp_strand((&__pyx_v_matches)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 629; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":630
 *     init_pp_strand(&reads)
 *     init_pp_strand(&matches)
 *     init_pp_strand(&mismatches)             # <<<<<<<<<<<<<<
 *     init_pp_strand(&deletions)
 *     init_pp_strand(&insertions)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_init_pp_strand((&__pyx_v_mismatches)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 630; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":631
 *     init_pp_strand(&matches)
 *     init_pp_strand(&mismatches)
 *     init_pp_strand(&deletions)             # <<<<<<<<<<<<<<
 *     init_pp_strand(&insertions)
 *     init_pp_strand(&A)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_init_pp_strand((&__pyx_v_deletions)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":632
 *     init_pp_strand(&mismatches)
 *     init_pp_strand(&deletions)
 *     init_pp_strand(&insertions)             # <<<<<<<<<<<<<<
 *     init_pp_strand(&A)
 *     init_pp_strand(&T)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_init_pp_strand((&__pyx_v_insertions)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":633
 *     init_pp_strand(&deletions)
 *     init_pp_strand(&insertions)
 *     init_pp_strand(&A)             # <<<<<<<<<<<<<<
 *     init_pp_strand(&T)
 *     init_pp_strand(&C)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_init_pp_strand((&__pyx_v_A)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 633; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":634
 *     init_pp_strand(&insertions)
 *     init_pp_strand(&A)
 *     init_pp_strand(&T)             # <<<<<<<<<<<<<<
 *     init_pp_strand(&C)
 *     init_pp_strand(&G)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_init_pp_strand((&__pyx_v_T)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 634; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":635
 *     init_pp_strand(&A)
 *     init_pp_strand(&T)
 *     init_pp_strand(&C)             # <<<<<<<<<<<<<<
 *     init_pp_strand(&G)
 *     init_pp_strand(&N)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_init_pp_strand((&__pyx_v_C)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":636
 *     init_pp_strand(&T)
 *     init_pp_strand(&C)
 *     init_pp_strand(&G)             # <<<<<<<<<<<<<<
 *     init_pp_strand(&N)
 * 
 */
  __pyx_t_1 = __pyx_f_10pysamstats_init_pp_strand((&__pyx_v_G)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":637
 *     init_pp_strand(&C)
 *     init_pp_strand(&G)
 *     init_pp_strand(&N)             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_1 = __pyx_f_10pysamstats_init_pp_strand((&__pyx_v_N)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 637; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":640
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 640; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":641
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # reference base
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":644
 * 
 *     # reference base
 *     refbase = fafile.fetch(reference=chrom, start=col.pos, end=col.pos+1).upper()             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_fafile), __pyx_n_s__fetch); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__reference), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = PyInt_FromLong(__pyx_v_col->pos); 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);
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__start), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyInt_FromLong((__pyx_v_col->pos + 1)); 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);
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__end), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_5)); 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_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__upper); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), 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_5); __pyx_t_5 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":647
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         # read.qpos
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":648
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         # read.qpos
 *         # read.is_del
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":652
 *         # read.is_del
 *         # read.indel
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":653
 *         # read.indel
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":654
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         incr_pp_strand(&reads, is_reverse, is_proper_pair)
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":655
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)             # <<<<<<<<<<<<<<
 *         incr_pp_strand(&reads, is_reverse, is_proper_pair)
 *         if read.is_del:
 */
    __pyx_v_is_reverse = ((int)(__pyx_v_flag & 16));

    /* "pysamstats.pyx":656
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         incr_pp_strand(&reads, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *         if read.is_del:
 *             incr_pp_strand(&deletions, is_reverse, is_proper_pair)
 */
    __pyx_t_1 = __pyx_f_10pysamstats_incr_pp_strand((&__pyx_v_reads), __pyx_v_is_reverse, __pyx_v_is_proper_pair); 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_1); __pyx_t_1 = 0;

    /* "pysamstats.pyx":657
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         incr_pp_strand(&reads, is_reverse, is_proper_pair)
 *         if read.is_del:             # <<<<<<<<<<<<<<
 *             incr_pp_strand(&deletions, is_reverse, is_proper_pair)
 *         else:
 */
    if (__pyx_v_read->is_del) {

      /* "pysamstats.pyx":658
 *         incr_pp_strand(&reads, is_reverse, is_proper_pair)
 *         if read.is_del:
 *             incr_pp_strand(&deletions, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *         else:
 *             alnbase = get_seq_base(aln, read.qpos)
 */
      __pyx_t_1 = __pyx_f_10pysamstats_incr_pp_strand((&__pyx_v_deletions), __pyx_v_is_reverse, __pyx_v_is_proper_pair); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 658; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L5;
    }
    /*else*/ {

      /* "pysamstats.pyx":660
 *             incr_pp_strand(&deletions, is_reverse, is_proper_pair)
 *         else:
 *             alnbase = get_seq_base(aln, read.qpos)             # <<<<<<<<<<<<<<
 *             if alnbase == 'A':
 *                 incr_pp_strand(&A, is_reverse, is_proper_pair)
 */
      __pyx_t_1 = __pyx_f_10pysamstats_get_seq_base(__pyx_v_aln, __pyx_v_read->qpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 660; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_v_alnbase);
      __pyx_v_alnbase = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "pysamstats.pyx":661
 *         else:
 *             alnbase = get_seq_base(aln, read.qpos)
 *             if alnbase == 'A':             # <<<<<<<<<<<<<<
 *                 incr_pp_strand(&A, is_reverse, is_proper_pair)
 *             elif alnbase == 'T':
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, ((PyObject *)__pyx_n_s__A), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":662
 *             alnbase = get_seq_base(aln, read.qpos)
 *             if alnbase == 'A':
 *                 incr_pp_strand(&A, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *             elif alnbase == 'T':
 *                 incr_pp_strand(&T, is_reverse, is_proper_pair)
 */
        __pyx_t_1 = __pyx_f_10pysamstats_incr_pp_strand((&__pyx_v_A), __pyx_v_is_reverse, __pyx_v_is_proper_pair); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 662; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L6;
      }

      /* "pysamstats.pyx":663
 *             if alnbase == 'A':
 *                 incr_pp_strand(&A, is_reverse, is_proper_pair)
 *             elif alnbase == 'T':             # <<<<<<<<<<<<<<
 *                 incr_pp_strand(&T, is_reverse, is_proper_pair)
 *             elif alnbase == 'C':
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, ((PyObject *)__pyx_n_s__T), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 663; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 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;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":664
 *                 incr_pp_strand(&A, is_reverse, is_proper_pair)
 *             elif alnbase == 'T':
 *                 incr_pp_strand(&T, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *             elif alnbase == 'C':
 *                 incr_pp_strand(&C, is_reverse, is_proper_pair)
 */
        __pyx_t_1 = __pyx_f_10pysamstats_incr_pp_strand((&__pyx_v_T), __pyx_v_is_reverse, __pyx_v_is_proper_pair); 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_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L6;
      }

      /* "pysamstats.pyx":665
 *             elif alnbase == 'T':
 *                 incr_pp_strand(&T, is_reverse, is_proper_pair)
 *             elif alnbase == 'C':             # <<<<<<<<<<<<<<
 *                 incr_pp_strand(&C, is_reverse, is_proper_pair)
 *             elif alnbase == 'G':
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, ((PyObject *)__pyx_n_s__C), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":666
 *                 incr_pp_strand(&T, is_reverse, is_proper_pair)
 *             elif alnbase == 'C':
 *                 incr_pp_strand(&C, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *             elif alnbase == 'G':
 *                 incr_pp_strand(&G, is_reverse, is_proper_pair)
 */
        __pyx_t_1 = __pyx_f_10pysamstats_incr_pp_strand((&__pyx_v_C), __pyx_v_is_reverse, __pyx_v_is_proper_pair); 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_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L6;
      }

      /* "pysamstats.pyx":667
 *             elif alnbase == 'C':
 *                 incr_pp_strand(&C, is_reverse, is_proper_pair)
 *             elif alnbase == 'G':             # <<<<<<<<<<<<<<
 *                 incr_pp_strand(&G, is_reverse, is_proper_pair)
 *             elif alnbase == 'N':
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, ((PyObject *)__pyx_n_s__G), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 667; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":668
 *                 incr_pp_strand(&C, is_reverse, is_proper_pair)
 *             elif alnbase == 'G':
 *                 incr_pp_strand(&G, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *             elif alnbase == 'N':
 *                 incr_pp_strand(&N, is_reverse, is_proper_pair)
 */
        __pyx_t_1 = __pyx_f_10pysamstats_incr_pp_strand((&__pyx_v_G), __pyx_v_is_reverse, __pyx_v_is_proper_pair); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 668; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L6;
      }

      /* "pysamstats.pyx":669
 *             elif alnbase == 'G':
 *                 incr_pp_strand(&G, is_reverse, is_proper_pair)
 *             elif alnbase == 'N':             # <<<<<<<<<<<<<<
 *                 incr_pp_strand(&N, is_reverse, is_proper_pair)
 *             if read.indel > 0:
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, ((PyObject *)__pyx_n_s__N), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 669; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":670
 *                 incr_pp_strand(&G, is_reverse, is_proper_pair)
 *             elif alnbase == 'N':
 *                 incr_pp_strand(&N, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *             if read.indel > 0:
 *                 incr_pp_strand(&insertions, is_reverse, is_proper_pair)
 */
        __pyx_t_1 = __pyx_f_10pysamstats_incr_pp_strand((&__pyx_v_N), __pyx_v_is_reverse, __pyx_v_is_proper_pair); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 670; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L6;
      }
      __pyx_L6:;

      /* "pysamstats.pyx":671
 *             elif alnbase == 'N':
 *                 incr_pp_strand(&N, is_reverse, is_proper_pair)
 *             if read.indel > 0:             # <<<<<<<<<<<<<<
 *                 incr_pp_strand(&insertions, is_reverse, is_proper_pair)
 *             if alnbase == refbase:
 */
      __pyx_t_10 = (__pyx_v_read->indel > 0);
      if (__pyx_t_10) {

        /* "pysamstats.pyx":672
 *                 incr_pp_strand(&N, is_reverse, is_proper_pair)
 *             if read.indel > 0:
 *                 incr_pp_strand(&insertions, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *             if alnbase == refbase:
 *                 incr_pp_strand(&matches, is_reverse, is_proper_pair)
 */
        __pyx_t_1 = __pyx_f_10pysamstats_incr_pp_strand((&__pyx_v_insertions), __pyx_v_is_reverse, __pyx_v_is_proper_pair); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L7;
      }
      __pyx_L7:;

      /* "pysamstats.pyx":673
 *             if read.indel > 0:
 *                 incr_pp_strand(&insertions, is_reverse, is_proper_pair)
 *             if alnbase == refbase:             # <<<<<<<<<<<<<<
 *                 incr_pp_strand(&matches, is_reverse, is_proper_pair)
 *             else:
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, __pyx_v_refbase, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":674
 *                 incr_pp_strand(&insertions, is_reverse, is_proper_pair)
 *             if alnbase == refbase:
 *                 incr_pp_strand(&matches, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 *             else:
 *                 incr_pp_strand(&mismatches, is_reverse, is_proper_pair)
 */
        __pyx_t_1 = __pyx_f_10pysamstats_incr_pp_strand((&__pyx_v_matches), __pyx_v_is_reverse, __pyx_v_is_proper_pair); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        goto __pyx_L8;
      }
      /*else*/ {

        /* "pysamstats.pyx":676
 *                 incr_pp_strand(&matches, is_reverse, is_proper_pair)
 *             else:
 *                 incr_pp_strand(&mismatches, is_reverse, is_proper_pair)             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
        __pyx_t_1 = __pyx_f_10pysamstats_incr_pp_strand((&__pyx_v_mismatches), __pyx_v_is_reverse, __pyx_v_is_proper_pair); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      }
      __pyx_L8:;
    }
    __pyx_L5:;
  }

  /* "pysamstats.pyx":678
 *                 incr_pp_strand(&mismatches, is_reverse, is_proper_pair)
 * 
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,             # <<<<<<<<<<<<<<
 *             'reads_all': n, 'reads_fwd': reads.fwd, 'reads_rev': reads.rev,
 *             'reads_pp': reads.pp, 'reads_pp_fwd': reads.pp_fwd, 'reads_pp_rev': reads.pp_rev,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__ref), __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":679
 * 
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 *             'reads_all': n, 'reads_fwd': reads.fwd, 'reads_rev': reads.rev,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads.pp, 'reads_pp_fwd': reads.pp_fwd, 'reads_pp_rev': reads.pp_rev,
 *             'matches': matches.all, 'matches_fwd': matches.fwd, 'matches_rev': matches.rev,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reads_all), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads.fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reads_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads.rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reads_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":680
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 *             'reads_all': n, 'reads_fwd': reads.fwd, 'reads_rev': reads.rev,
 *             'reads_pp': reads.pp, 'reads_pp_fwd': reads.pp_fwd, 'reads_pp_rev': reads.pp_rev,             # <<<<<<<<<<<<<<
 *             'matches': matches.all, 'matches_fwd': matches.fwd, 'matches_rev': matches.rev,
 *             'matches_pp': matches.pp, 'matches_pp_fwd': matches.pp_fwd, 'matches_pp_rev': matches.pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads.pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reads_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads.pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reads_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads.pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 680; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reads_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":681
 *             'reads_all': n, 'reads_fwd': reads.fwd, 'reads_rev': reads.rev,
 *             'reads_pp': reads.pp, 'reads_pp_fwd': reads.pp_fwd, 'reads_pp_rev': reads.pp_rev,
 *             'matches': matches.all, 'matches_fwd': matches.fwd, 'matches_rev': matches.rev,             # <<<<<<<<<<<<<<
 *             'matches_pp': matches.pp, 'matches_pp_fwd': matches.pp_fwd, 'matches_pp_rev': matches.pp_rev,
 *             'mismatches': mismatches.all, 'mismatches_fwd': mismatches.fwd, 'mismatches_rev': mismatches.rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_matches.all); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__matches), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_matches.fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__matches_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_matches.rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 681; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__matches_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":682
 *             'reads_pp': reads.pp, 'reads_pp_fwd': reads.pp_fwd, 'reads_pp_rev': reads.pp_rev,
 *             'matches': matches.all, 'matches_fwd': matches.fwd, 'matches_rev': matches.rev,
 *             'matches_pp': matches.pp, 'matches_pp_fwd': matches.pp_fwd, 'matches_pp_rev': matches.pp_rev,             # <<<<<<<<<<<<<<
 *             'mismatches': mismatches.all, 'mismatches_fwd': mismatches.fwd, 'mismatches_rev': mismatches.rev,
 *             'mismatches_pp': mismatches.pp, 'mismatches_pp_fwd': mismatches.pp_fwd, 'mismatches_pp_rev': mismatches.pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_matches.pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__matches_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_matches.pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__matches_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_matches.pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 682; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__matches_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":683
 *             'matches': matches.all, 'matches_fwd': matches.fwd, 'matches_rev': matches.rev,
 *             'matches_pp': matches.pp, 'matches_pp_fwd': matches.pp_fwd, 'matches_pp_rev': matches.pp_rev,
 *             'mismatches': mismatches.all, 'mismatches_fwd': mismatches.fwd, 'mismatches_rev': mismatches.rev,             # <<<<<<<<<<<<<<
 *             'mismatches_pp': mismatches.pp, 'mismatches_pp_fwd': mismatches.pp_fwd, 'mismatches_pp_rev': mismatches.pp_rev,
 *             'deletions': deletions.all, 'deletions_fwd': deletions.fwd, 'deletions_rev': deletions.rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_mismatches.all); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mismatches), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_mismatches.fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mismatches_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_mismatches.rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 683; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mismatches_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":684
 *             'matches_pp': matches.pp, 'matches_pp_fwd': matches.pp_fwd, 'matches_pp_rev': matches.pp_rev,
 *             'mismatches': mismatches.all, 'mismatches_fwd': mismatches.fwd, 'mismatches_rev': mismatches.rev,
 *             'mismatches_pp': mismatches.pp, 'mismatches_pp_fwd': mismatches.pp_fwd, 'mismatches_pp_rev': mismatches.pp_rev,             # <<<<<<<<<<<<<<
 *             'deletions': deletions.all, 'deletions_fwd': deletions.fwd, 'deletions_rev': deletions.rev,
 *             'deletions_pp': deletions.pp, 'deletions_pp_fwd': deletions.pp_fwd, 'deletions_pp_rev': deletions.pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_mismatches.pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mismatches_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_mismatches.pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mismatches_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_mismatches.pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 684; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__mismatches_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":685
 *             'mismatches': mismatches.all, 'mismatches_fwd': mismatches.fwd, 'mismatches_rev': mismatches.rev,
 *             'mismatches_pp': mismatches.pp, 'mismatches_pp_fwd': mismatches.pp_fwd, 'mismatches_pp_rev': mismatches.pp_rev,
 *             'deletions': deletions.all, 'deletions_fwd': deletions.fwd, 'deletions_rev': deletions.rev,             # <<<<<<<<<<<<<<
 *             'deletions_pp': deletions.pp, 'deletions_pp_fwd': deletions.pp_fwd, 'deletions_pp_rev': deletions.pp_rev,
 *             'insertions': insertions.all, 'insertions_fwd': insertions.fwd, 'insertions_rev': insertions.rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_deletions.all); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__deletions), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_deletions.fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__deletions_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_deletions.rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__deletions_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":686
 *             'mismatches_pp': mismatches.pp, 'mismatches_pp_fwd': mismatches.pp_fwd, 'mismatches_pp_rev': mismatches.pp_rev,
 *             'deletions': deletions.all, 'deletions_fwd': deletions.fwd, 'deletions_rev': deletions.rev,
 *             'deletions_pp': deletions.pp, 'deletions_pp_fwd': deletions.pp_fwd, 'deletions_pp_rev': deletions.pp_rev,             # <<<<<<<<<<<<<<
 *             'insertions': insertions.all, 'insertions_fwd': insertions.fwd, 'insertions_rev': insertions.rev,
 *             'insertions_pp': insertions.pp, 'insertions_pp_fwd': insertions.pp_fwd, 'insertions_pp_rev': insertions.pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_deletions.pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__deletions_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_deletions.pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__deletions_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_deletions.pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 686; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__deletions_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":687
 *             'deletions': deletions.all, 'deletions_fwd': deletions.fwd, 'deletions_rev': deletions.rev,
 *             'deletions_pp': deletions.pp, 'deletions_pp_fwd': deletions.pp_fwd, 'deletions_pp_rev': deletions.pp_rev,
 *             'insertions': insertions.all, 'insertions_fwd': insertions.fwd, 'insertions_rev': insertions.rev,             # <<<<<<<<<<<<<<
 *             'insertions_pp': insertions.pp, 'insertions_pp_fwd': insertions.pp_fwd, 'insertions_pp_rev': insertions.pp_rev,
 *             'A': A.all, 'A_fwd': A.fwd, 'A_rev': A.rev, 'A_pp': A.pp, 'A_pp_fwd': A.pp_fwd, 'A_pp_rev': A.pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_insertions.all); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__insertions), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_insertions.fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__insertions_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_insertions.rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__insertions_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":688
 *             'deletions_pp': deletions.pp, 'deletions_pp_fwd': deletions.pp_fwd, 'deletions_pp_rev': deletions.pp_rev,
 *             'insertions': insertions.all, 'insertions_fwd': insertions.fwd, 'insertions_rev': insertions.rev,
 *             'insertions_pp': insertions.pp, 'insertions_pp_fwd': insertions.pp_fwd, 'insertions_pp_rev': insertions.pp_rev,             # <<<<<<<<<<<<<<
 *             'A': A.all, 'A_fwd': A.fwd, 'A_rev': A.rev, 'A_pp': A.pp, 'A_pp_fwd': A.pp_fwd, 'A_pp_rev': A.pp_rev,
 *             'C': C.all, 'C_fwd': C.fwd, 'C_rev': C.rev, 'C_pp': C.pp, 'C_pp_fwd': C.pp_fwd, 'C_pp_rev': C.pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_insertions.pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__insertions_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_insertions.pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__insertions_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_insertions.pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 688; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__insertions_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":689
 *             'insertions': insertions.all, 'insertions_fwd': insertions.fwd, 'insertions_rev': insertions.rev,
 *             'insertions_pp': insertions.pp, 'insertions_pp_fwd': insertions.pp_fwd, 'insertions_pp_rev': insertions.pp_rev,
 *             'A': A.all, 'A_fwd': A.fwd, 'A_rev': A.rev, 'A_pp': A.pp, 'A_pp_fwd': A.pp_fwd, 'A_pp_rev': A.pp_rev,             # <<<<<<<<<<<<<<
 *             'C': C.all, 'C_fwd': C.fwd, 'C_rev': C.rev, 'C_pp': C.pp, 'C_pp_fwd': C.pp_fwd, 'C_pp_rev': C.pp_rev,
 *             'T': T.all, 'T_fwd': T.fwd, 'T_rev': T.rev, 'T_pp': T.pp, 'T_pp_fwd': T.pp_fwd, 'T_pp_rev': T.pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_A.all); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__A), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_A.fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__A_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_A.rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__A_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_A.pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__A_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_A.pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__A_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_A.pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 689; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__A_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":690
 *             'insertions_pp': insertions.pp, 'insertions_pp_fwd': insertions.pp_fwd, 'insertions_pp_rev': insertions.pp_rev,
 *             'A': A.all, 'A_fwd': A.fwd, 'A_rev': A.rev, 'A_pp': A.pp, 'A_pp_fwd': A.pp_fwd, 'A_pp_rev': A.pp_rev,
 *             'C': C.all, 'C_fwd': C.fwd, 'C_rev': C.rev, 'C_pp': C.pp, 'C_pp_fwd': C.pp_fwd, 'C_pp_rev': C.pp_rev,             # <<<<<<<<<<<<<<
 *             'T': T.all, 'T_fwd': T.fwd, 'T_rev': T.rev, 'T_pp': T.pp, 'T_pp_fwd': T.pp_fwd, 'T_pp_rev': T.pp_rev,
 *             'G': G.all, 'G_fwd': G.fwd, 'G_rev': G.rev, 'G_pp': G.pp, 'G_pp_fwd': G.pp_fwd, 'G_pp_rev': G.pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_C.all); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__C), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_C.fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__C_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_C.rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__C_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_C.pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__C_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_C.pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__C_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_C.pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 690; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__C_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":691
 *             'A': A.all, 'A_fwd': A.fwd, 'A_rev': A.rev, 'A_pp': A.pp, 'A_pp_fwd': A.pp_fwd, 'A_pp_rev': A.pp_rev,
 *             'C': C.all, 'C_fwd': C.fwd, 'C_rev': C.rev, 'C_pp': C.pp, 'C_pp_fwd': C.pp_fwd, 'C_pp_rev': C.pp_rev,
 *             'T': T.all, 'T_fwd': T.fwd, 'T_rev': T.rev, 'T_pp': T.pp, 'T_pp_fwd': T.pp_fwd, 'T_pp_rev': T.pp_rev,             # <<<<<<<<<<<<<<
 *             'G': G.all, 'G_fwd': G.fwd, 'G_rev': G.rev, 'G_pp': G.pp, 'G_pp_fwd': G.pp_fwd, 'G_pp_rev': G.pp_rev,
 *             'N': N.all, 'N_fwd': N.fwd, 'N_rev': N.rev, 'N_pp': N.pp, 'N_pp_fwd': N.pp_fwd, 'N_pp_rev': N.pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_T.all); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__T), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_T.fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__T_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_T.rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__T_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_T.pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__T_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_T.pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__T_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_T.pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 691; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__T_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":692
 *             'C': C.all, 'C_fwd': C.fwd, 'C_rev': C.rev, 'C_pp': C.pp, 'C_pp_fwd': C.pp_fwd, 'C_pp_rev': C.pp_rev,
 *             'T': T.all, 'T_fwd': T.fwd, 'T_rev': T.rev, 'T_pp': T.pp, 'T_pp_fwd': T.pp_fwd, 'T_pp_rev': T.pp_rev,
 *             'G': G.all, 'G_fwd': G.fwd, 'G_rev': G.rev, 'G_pp': G.pp, 'G_pp_fwd': G.pp_fwd, 'G_pp_rev': G.pp_rev,             # <<<<<<<<<<<<<<
 *             'N': N.all, 'N_fwd': N.fwd, 'N_rev': N.rev, 'N_pp': N.pp, 'N_pp_fwd': N.pp_fwd, 'N_pp_rev': N.pp_rev,
 *             }
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_G.all); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__G), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_G.fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__G_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_G.rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__G_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_G.pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__G_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_G.pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__G_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_G.pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__G_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":693
 *             'T': T.all, 'T_fwd': T.fwd, 'T_rev': T.rev, 'T_pp': T.pp, 'T_pp_fwd': T.pp_fwd, 'T_pp_rev': T.pp_rev,
 *             'G': G.all, 'G_fwd': G.fwd, 'G_rev': G.rev, 'G_pp': G.pp, 'G_pp_fwd': G.pp_fwd, 'G_pp_rev': G.pp_rev,
 *             'N': N.all, 'N_fwd': N.fwd, 'N_rev': N.rev, 'N_pp': N.pp, 'N_pp_fwd': N.pp_fwd, 'N_pp_rev': N.pp_rev,             # <<<<<<<<<<<<<<
 *             }
 * 
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_N.all); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__N), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_N.fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__N_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_N.rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__N_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_N.pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__N_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_N.pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__N_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_N.pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 693; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__N_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_variation_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_refbase);
  __Pyx_XDECREF(__pyx_v_alnbase);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_36construct_rec_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_36construct_rec_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_variation_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__fafile,&__pyx_n_s__col,&__pyx_n_s__one_based,0};
    PyObject* values[4] = {0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_variation_strand", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_variation_strand", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_variation_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __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);
        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_9csamtools_Samfile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[2]);
    if (values[3]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":612
 * 
 * cpdef object construct_rec_variation_strand(Samfile samfile, Fastafile fafile,
 *                                             PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_variation_strand", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_variation_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_35construct_rec_variation_strand(__pyx_self, __pyx_v_samfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":611
 * 
 * 
 * cpdef object construct_rec_variation_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                             PileupProxy col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pf_10pysamstats_35construct_rec_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_variation_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_variation_strand", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_variation_strand(__pyx_v_samfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_variation_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_39generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_38stat_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_38stat_variation_strand = {__Pyx_NAMESTR("stat_variation_strand"), (PyCFunction)__pyx_pw_10pysamstats_38stat_variation_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_38stat_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_variation_strand (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__samfile,&__pyx_n_s__fafile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "pysamstats.pyx":698
 * 
 * def stat_variation_strand(Samfile samfile, Fastafile fafile,
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    values[5] = __pyx_k_23;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        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__fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stat_variation_strand", 0, 2, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__chrom);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_variation_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)values[1]);
    __pyx_v_chrom = values[2];
    __pyx_v_start = values[3];
    __pyx_v_end = values[4];
    __pyx_v_one_based = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_variation_strand", 0, 2, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_variation_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_37stat_variation_strand(__pyx_self, __pyx_v_samfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":697
 * 
 * 
 * def stat_variation_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */

static PyObject *__pyx_pf_10pysamstats_37stat_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_variation_strand", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *)__pyx_ptype_10pysamstats___pyx_scope_struct_5_stat_variation_strand->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_5_stat_variation_strand, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_fafile = __pyx_v_fafile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_39generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_variation_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_39generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_variation_strand __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":699
 * def stat_variation_strand(Samfile samfile, Fastafile fafile,
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_variation_strand(samfile, fafile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 699; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":700
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_variation_strand(samfile, fafile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 700; __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 = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 700; __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 = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 700; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":701
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_variation_strand(samfile, fafile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_variation_strand(__pyx_cur_scope->__pyx_v_samfile, __pyx_cur_scope->__pyx_v_fafile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_variation_strand", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_41write_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_41write_variation_strand = {__Pyx_NAMESTR("write_variation_strand"), (PyCFunction)__pyx_pw_10pysamstats_41write_variation_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_41write_variation_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_variation_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_variation_strand", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_40write_variation_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":704
 * 
 * 
 * def write_variation_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 *                 'reads_all', 'reads_fwd', 'reads_rev', 'reads_pp', 'reads_pp_fwd', 'reads_pp_rev',
 */

static PyObject *__pyx_pf_10pysamstats_40write_variation_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_variation_strand", 0);

  /* "pysamstats.pyx":705
 * 
 * def write_variation_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'ref',             # <<<<<<<<<<<<<<
 *                 'reads_all', 'reads_fwd', 'reads_rev', 'reads_pp', 'reads_pp_fwd', 'reads_pp_rev',
 *                 'matches', 'matches_fwd', 'matches_rev', 'matches_pp', 'matches_pp_fwd', 'matches_pp_rev',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_24));
  __pyx_v_fieldnames = __pyx_k_tuple_24;

  /* "pysamstats.pyx":716
 *                 'G', 'G_fwd', 'G_rev', 'G_pp', 'G_pp_fwd', 'G_pp_rev',
 *                 'N', 'N_fwd', 'N_rev', 'N_pp', 'N_pp_fwd', 'N_pp_rev')
 *     write_stats(stat_variation_strand, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s_25); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __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 = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 716; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_variation_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":724
 * 
 * 
 * cpdef object construct_rec_tlen(Samfile samfile, PileupProxy col,             # <<<<<<<<<<<<<<
 *                                 bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_43construct_rec_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_tlen(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_tlen *__pyx_optional_args) {

  /* "pysamstats.pyx":725
 * 
 * cpdef object construct_rec_tlen(Samfile samfile, PileupProxy col,
 *                                 bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_mate_other_chr;
  unsigned int __pyx_v_reads_p;
  unsigned int __pyx_v_reads_pp;
  int64_t __pyx_v_tlen;
  int64_t __pyx_v_tlen_squared;
  int64_t __pyx_v_tlen_p_sum;
  double __pyx_v_tlen_p_mean;
  double __pyx_v_tlen_p_dev_squared;
  double __pyx_v_tlen_p_dev_squared_sum;
  int64_t __pyx_v_tlen_p_squared_sum;
  int64_t __pyx_v_tlen_pp_sum;
  double __pyx_v_tlen_pp_mean;
  double __pyx_v_tlen_pp_dev_squared;
  double __pyx_v_tlen_pp_dev_squared_sum;
  int64_t __pyx_v_tlen_pp_squared_sum;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  int __pyx_v_mate_is_unmapped;
  PyObject *__pyx_v_mean_tlen = NULL;
  PyObject *__pyx_v_rms_tlen = NULL;
  double __pyx_v_variance_tlen;
  PyObject *__pyx_v_std_tlen = NULL;
  PyObject *__pyx_v_mean_tlen_pp = NULL;
  PyObject *__pyx_v_rms_tlen_pp = NULL;
  double __pyx_v_variance_tlen_pp;
  PyObject *__pyx_v_std_tlen_pp = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int32_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  double __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_tlen", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":737
 *     cdef bint mate_is_unmappped
 *     cdef bint mate_other_chr
 *     cdef unsigned int reads_p = 0 # reads "paired", i.e., mate is mapped to same chromosome, so tlen is meaningful             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp = 0 # reads "properly paired", as defined by aligner
 *     cdef int64_t tlen
 */
  __pyx_v_reads_p = 0;

  /* "pysamstats.pyx":738
 *     cdef bint mate_other_chr
 *     cdef unsigned int reads_p = 0 # reads "paired", i.e., mate is mapped to same chromosome, so tlen is meaningful
 *     cdef unsigned int reads_pp = 0 # reads "properly paired", as defined by aligner             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen
 *     cdef int64_t tlen_squared
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":741
 *     cdef int64_t tlen
 *     cdef int64_t tlen_squared
 *     cdef int64_t tlen_p_sum = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_p_mean = 0
 *     cdef double tlen_p_dev_squared
 */
  __pyx_v_tlen_p_sum = 0;

  /* "pysamstats.pyx":742
 *     cdef int64_t tlen_squared
 *     cdef int64_t tlen_p_sum = 0
 *     cdef double tlen_p_mean = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_p_dev_squared
 *     cdef double tlen_p_dev_squared_sum = 0
 */
  __pyx_v_tlen_p_mean = 0.0;

  /* "pysamstats.pyx":744
 *     cdef double tlen_p_mean = 0
 *     cdef double tlen_p_dev_squared
 *     cdef double tlen_p_dev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_p_squared_sum = 0
 *     cdef int64_t tlen_pp_sum = 0
 */
  __pyx_v_tlen_p_dev_squared_sum = 0.0;

  /* "pysamstats.pyx":745
 *     cdef double tlen_p_dev_squared
 *     cdef double tlen_p_dev_squared_sum = 0
 *     cdef int64_t tlen_p_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_pp_sum = 0
 *     cdef double tlen_pp_mean = 0
 */
  __pyx_v_tlen_p_squared_sum = 0;

  /* "pysamstats.pyx":746
 *     cdef double tlen_p_dev_squared_sum = 0
 *     cdef int64_t tlen_p_squared_sum = 0
 *     cdef int64_t tlen_pp_sum = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_pp_mean = 0
 *     cdef double tlen_pp_dev_squared
 */
  __pyx_v_tlen_pp_sum = 0;

  /* "pysamstats.pyx":747
 *     cdef int64_t tlen_p_squared_sum = 0
 *     cdef int64_t tlen_pp_sum = 0
 *     cdef double tlen_pp_mean = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_pp_dev_squared
 *     cdef double tlen_pp_dev_squared_sum = 0
 */
  __pyx_v_tlen_pp_mean = 0.0;

  /* "pysamstats.pyx":749
 *     cdef double tlen_pp_mean = 0
 *     cdef double tlen_pp_dev_squared
 *     cdef double tlen_pp_dev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_pp_squared_sum = 0
 * 
 */
  __pyx_v_tlen_pp_dev_squared_sum = 0.0;

  /* "pysamstats.pyx":750
 *     cdef double tlen_pp_dev_squared
 *     cdef double tlen_pp_dev_squared_sum = 0
 *     cdef int64_t tlen_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_tlen_pp_squared_sum = 0;

  /* "pysamstats.pyx":753
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 753; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":754
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":757
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 757; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 757; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":758
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":761
 * 
 *     # loop over reads
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":762
 *     # loop over reads
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":763
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 * 
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":764
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 * 
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":766
 *         flag = aln.core.flag
 * 
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":767
 * 
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)             # <<<<<<<<<<<<<<
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)
 * 
 */
    __pyx_v_mate_is_unmapped = ((int)(__pyx_v_flag & 8));

    /* "pysamstats.pyx":768
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)             # <<<<<<<<<<<<<<
 * 
 *         # N.B., pysam exposes this property as 'tlen' rather than 'isize' so we
 */
    __pyx_v_mate_other_chr = ((int)(__pyx_v_aln->core.tid != __pyx_v_aln->core.mtid));

    /* "pysamstats.pyx":772
 *         # N.B., pysam exposes this property as 'tlen' rather than 'isize' so we
 *         # follow their naming convention
 *         tlen = aln.core.isize             # <<<<<<<<<<<<<<
 *         tlen_squared = tlen**2
 * 
 */
    __pyx_t_10 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_10;

    /* "pysamstats.pyx":773
 *         # follow their naming convention
 *         tlen = aln.core.isize
 *         tlen_squared = tlen**2             # <<<<<<<<<<<<<<
 * 
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 */
    __pyx_v_tlen_squared = __Pyx_pow_long(((long)__pyx_v_tlen), 2);

    /* "pysamstats.pyx":776
 * 
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 *         if not mate_is_unmapped and not mate_other_chr:             # <<<<<<<<<<<<<<
 *             reads_p += 1
 *             tlen_p_sum += tlen
 */
    __pyx_t_11 = (!__pyx_v_mate_is_unmapped);
    if (__pyx_t_11) {
      __pyx_t_12 = (!__pyx_v_mate_other_chr);
      __pyx_t_13 = __pyx_t_12;
    } else {
      __pyx_t_13 = __pyx_t_11;
    }
    if (__pyx_t_13) {

      /* "pysamstats.pyx":777
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 *         if not mate_is_unmapped and not mate_other_chr:
 *             reads_p += 1             # <<<<<<<<<<<<<<
 *             tlen_p_sum += tlen
 *             tlen_p_squared_sum += tlen_squared
 */
      __pyx_v_reads_p = (__pyx_v_reads_p + 1);

      /* "pysamstats.pyx":778
 *         if not mate_is_unmapped and not mate_other_chr:
 *             reads_p += 1
 *             tlen_p_sum += tlen             # <<<<<<<<<<<<<<
 *             tlen_p_squared_sum += tlen_squared
 *             if is_proper_pair:
 */
      __pyx_v_tlen_p_sum = (__pyx_v_tlen_p_sum + __pyx_v_tlen);

      /* "pysamstats.pyx":779
 *             reads_p += 1
 *             tlen_p_sum += tlen
 *             tlen_p_squared_sum += tlen_squared             # <<<<<<<<<<<<<<
 *             if is_proper_pair:
 *                 reads_pp += 1
 */
      __pyx_v_tlen_p_squared_sum = (__pyx_v_tlen_p_squared_sum + __pyx_v_tlen_squared);

      /* "pysamstats.pyx":780
 *             tlen_p_sum += tlen
 *             tlen_p_squared_sum += tlen_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp += 1
 *                 tlen_pp_sum += tlen
 */
      if (__pyx_v_is_proper_pair) {

        /* "pysamstats.pyx":781
 *             tlen_p_squared_sum += tlen_squared
 *             if is_proper_pair:
 *                 reads_pp += 1             # <<<<<<<<<<<<<<
 *                 tlen_pp_sum += tlen
 *                 tlen_pp_squared_sum += tlen_squared
 */
        __pyx_v_reads_pp = (__pyx_v_reads_pp + 1);

        /* "pysamstats.pyx":782
 *             if is_proper_pair:
 *                 reads_pp += 1
 *                 tlen_pp_sum += tlen             # <<<<<<<<<<<<<<
 *                 tlen_pp_squared_sum += tlen_squared
 * 
 */
        __pyx_v_tlen_pp_sum = (__pyx_v_tlen_pp_sum + __pyx_v_tlen);

        /* "pysamstats.pyx":783
 *                 reads_pp += 1
 *                 tlen_pp_sum += tlen
 *                 tlen_pp_squared_sum += tlen_squared             # <<<<<<<<<<<<<<
 * 
 *     # calculate intermediate variables
 */
        __pyx_v_tlen_pp_squared_sum = (__pyx_v_tlen_pp_squared_sum + __pyx_v_tlen_squared);
        goto __pyx_L6;
      }
      __pyx_L6:;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  /* "pysamstats.pyx":786
 * 
 *     # calculate intermediate variables
 *     if reads_p > 0:             # <<<<<<<<<<<<<<
 *         tlen_p_mean = tlen_p_sum * 1. / reads_p
 *     if reads_pp > 0:
 */
  __pyx_t_13 = (__pyx_v_reads_p > 0);
  if (__pyx_t_13) {

    /* "pysamstats.pyx":787
 *     # calculate intermediate variables
 *     if reads_p > 0:
 *         tlen_p_mean = tlen_p_sum * 1. / reads_p             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         tlen_pp_mean = tlen_pp_sum * 1. / reads_pp
 */
    __pyx_t_14 = (__pyx_v_tlen_p_sum * 1.);
    if (unlikely(__pyx_v_reads_p == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_tlen_p_mean = (__pyx_t_14 / __pyx_v_reads_p);
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "pysamstats.pyx":788
 *     if reads_p > 0:
 *         tlen_p_mean = tlen_p_sum * 1. / reads_p
 *     if reads_pp > 0:             # <<<<<<<<<<<<<<
 *         tlen_pp_mean = tlen_pp_sum * 1. / reads_pp
 * 
 */
  __pyx_t_13 = (__pyx_v_reads_pp > 0);
  if (__pyx_t_13) {

    /* "pysamstats.pyx":789
 *         tlen_p_mean = tlen_p_sum * 1. / reads_p
 *     if reads_pp > 0:
 *         tlen_pp_mean = tlen_pp_sum * 1. / reads_pp             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads again to calculate variance (and hence std)
 */
    __pyx_t_14 = (__pyx_v_tlen_pp_sum * 1.);
    if (unlikely(__pyx_v_reads_pp == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 789; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_tlen_pp_mean = (__pyx_t_14 / __pyx_v_reads_pp);
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "pysamstats.pyx":792
 * 
 *     # loop over reads again to calculate variance (and hence std)
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":793
 *     # loop over reads again to calculate variance (and hence std)
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":794
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":795
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":796
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":797
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)             # <<<<<<<<<<<<<<
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)
 *         tlen = aln.core.isize
 */
    __pyx_v_mate_is_unmapped = ((int)(__pyx_v_flag & 8));

    /* "pysamstats.pyx":798
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)             # <<<<<<<<<<<<<<
 *         tlen = aln.core.isize
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 */
    __pyx_v_mate_other_chr = ((int)(__pyx_v_aln->core.tid != __pyx_v_aln->core.mtid));

    /* "pysamstats.pyx":799
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)
 *         tlen = aln.core.isize             # <<<<<<<<<<<<<<
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 *         if not mate_is_unmapped and not mate_other_chr:
 */
    __pyx_t_10 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_10;

    /* "pysamstats.pyx":801
 *         tlen = aln.core.isize
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 *         if not mate_is_unmapped and not mate_other_chr:             # <<<<<<<<<<<<<<
 *             tlen_p_dev_squared = (tlen - tlen_p_mean)**2
 *             tlen_p_dev_squared_sum += tlen_p_dev_squared
 */
    __pyx_t_13 = (!__pyx_v_mate_is_unmapped);
    if (__pyx_t_13) {
      __pyx_t_11 = (!__pyx_v_mate_other_chr);
      __pyx_t_12 = __pyx_t_11;
    } else {
      __pyx_t_12 = __pyx_t_13;
    }
    if (__pyx_t_12) {

      /* "pysamstats.pyx":802
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 *         if not mate_is_unmapped and not mate_other_chr:
 *             tlen_p_dev_squared = (tlen - tlen_p_mean)**2             # <<<<<<<<<<<<<<
 *             tlen_p_dev_squared_sum += tlen_p_dev_squared
 *             if is_proper_pair:
 */
      __pyx_v_tlen_p_dev_squared = pow((__pyx_v_tlen - __pyx_v_tlen_p_mean), 2.0);

      /* "pysamstats.pyx":803
 *         if not mate_is_unmapped and not mate_other_chr:
 *             tlen_p_dev_squared = (tlen - tlen_p_mean)**2
 *             tlen_p_dev_squared_sum += tlen_p_dev_squared             # <<<<<<<<<<<<<<
 *             if is_proper_pair:
 *                 tlen_pp_dev_squared = (tlen - tlen_pp_mean)**2
 */
      __pyx_v_tlen_p_dev_squared_sum = (__pyx_v_tlen_p_dev_squared_sum + __pyx_v_tlen_p_dev_squared);

      /* "pysamstats.pyx":804
 *             tlen_p_dev_squared = (tlen - tlen_p_mean)**2
 *             tlen_p_dev_squared_sum += tlen_p_dev_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 tlen_pp_dev_squared = (tlen - tlen_pp_mean)**2
 *                 tlen_pp_dev_squared_sum += tlen_pp_dev_squared
 */
      if (__pyx_v_is_proper_pair) {

        /* "pysamstats.pyx":805
 *             tlen_p_dev_squared_sum += tlen_p_dev_squared
 *             if is_proper_pair:
 *                 tlen_pp_dev_squared = (tlen - tlen_pp_mean)**2             # <<<<<<<<<<<<<<
 *                 tlen_pp_dev_squared_sum += tlen_pp_dev_squared
 * 
 */
        __pyx_v_tlen_pp_dev_squared = pow((__pyx_v_tlen - __pyx_v_tlen_pp_mean), 2.0);

        /* "pysamstats.pyx":806
 *             if is_proper_pair:
 *                 tlen_pp_dev_squared = (tlen - tlen_pp_mean)**2
 *                 tlen_pp_dev_squared_sum += tlen_pp_dev_squared             # <<<<<<<<<<<<<<
 * 
 *     # calculate output variables
 */
        __pyx_v_tlen_pp_dev_squared_sum = (__pyx_v_tlen_pp_dev_squared_sum + __pyx_v_tlen_pp_dev_squared);
        goto __pyx_L12;
      }
      __pyx_L12:;
      goto __pyx_L11;
    }
    __pyx_L11:;
  }

  /* "pysamstats.pyx":811
 *     # N.B. round values to nearest integer, any finer precision is probably not
 *     # interesting
 *     if reads_p > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen = int(round(tlen_p_mean))
 *         rms_tlen = int(round(sqrt(tlen_p_squared_sum * 1. / reads_p)))
 */
  __pyx_t_12 = (__pyx_v_reads_p > 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":812
 *     # interesting
 *     if reads_p > 0:
 *         mean_tlen = int(round(tlen_p_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen = int(round(sqrt(tlen_p_squared_sum * 1. / reads_p)))
 *         variance_tlen = tlen_p_dev_squared_sum * 1. / reads_p
 */
    __pyx_t_4 = PyFloat_FromDouble(__pyx_v_tlen_p_mean); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_mean_tlen = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":813
 *     if reads_p > 0:
 *         mean_tlen = int(round(tlen_p_mean))
 *         rms_tlen = int(round(sqrt(tlen_p_squared_sum * 1. / reads_p)))             # <<<<<<<<<<<<<<
 *         variance_tlen = tlen_p_dev_squared_sum * 1. / reads_p
 *         std_tlen = int(round(sqrt(variance_tlen)))
 */
    __pyx_t_14 = (__pyx_v_tlen_p_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_p == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_14 / __pyx_v_reads_p))); 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_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), 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(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 813; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), 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(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_tlen = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":814
 *         mean_tlen = int(round(tlen_p_mean))
 *         rms_tlen = int(round(sqrt(tlen_p_squared_sum * 1. / reads_p)))
 *         variance_tlen = tlen_p_dev_squared_sum * 1. / reads_p             # <<<<<<<<<<<<<<
 *         std_tlen = int(round(sqrt(variance_tlen)))
 *     else:
 */
    __pyx_t_14 = (__pyx_v_tlen_p_dev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_p == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 814; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen = (__pyx_t_14 / __pyx_v_reads_p);

    /* "pysamstats.pyx":815
 *         rms_tlen = int(round(sqrt(tlen_p_squared_sum * 1. / reads_p)))
 *         variance_tlen = tlen_p_dev_squared_sum * 1. / reads_p
 *         std_tlen = int(round(sqrt(variance_tlen)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = 'NA'
 */
    __pyx_t_4 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 815; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 815; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 815; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_std_tlen = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L13;
  }
  /*else*/ {

    /* "pysamstats.pyx":817
 *         std_tlen = int(round(sqrt(variance_tlen)))
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = 'NA'             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_tlen = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_std_tlen = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_mean_tlen = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L13:;

  /* "pysamstats.pyx":818
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = 'NA'
 *     if reads_pp > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = int(round(sqrt(tlen_pp_squared_sum * 1. / reads_pp)))
 */
  __pyx_t_12 = (__pyx_v_reads_pp > 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":819
 *         rms_tlen = std_tlen = mean_tlen = 'NA'
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_pp = int(round(sqrt(tlen_pp_squared_sum * 1. / reads_pp)))
 *         variance_tlen_pp = tlen_pp_dev_squared_sum * 1. / reads_pp
 */
    __pyx_t_4 = PyFloat_FromDouble(__pyx_v_tlen_pp_mean); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 819; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_mean_tlen_pp = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":820
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = int(round(sqrt(tlen_pp_squared_sum * 1. / reads_pp)))             # <<<<<<<<<<<<<<
 *         variance_tlen_pp = tlen_pp_dev_squared_sum * 1. / reads_pp
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 */
    __pyx_t_14 = (__pyx_v_tlen_pp_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_14 / __pyx_v_reads_pp))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 820; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_tlen_pp = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":821
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = int(round(sqrt(tlen_pp_squared_sum * 1. / reads_pp)))
 *         variance_tlen_pp = tlen_pp_dev_squared_sum * 1. / reads_pp             # <<<<<<<<<<<<<<
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 *     else:
 */
    __pyx_t_14 = (__pyx_v_tlen_pp_dev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_pp = (__pyx_t_14 / __pyx_v_reads_pp);

    /* "pysamstats.pyx":822
 *         rms_tlen_pp = int(round(sqrt(tlen_pp_squared_sum * 1. / reads_pp)))
 *         variance_tlen_pp = tlen_pp_dev_squared_sum * 1. / reads_pp
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 'NA'
 */
    __pyx_t_4 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_pp)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 822; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_std_tlen_pp = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L14;
  }
  /*else*/ {

    /* "pysamstats.pyx":824
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 *     else:
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 'NA'             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom,
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_tlen_pp = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_std_tlen_pp = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_mean_tlen_pp = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L14:;

  /* "pysamstats.pyx":826
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 'NA'
 * 
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 * #            'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":827
 * 
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 * #            'reads_all': n,
 * #            'reads_paired': reads_p,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":831
 * #            'reads_paired': reads_p,
 * #            'reads_pp': reads_pp,
 *             'mean_tlen': mean_tlen,             # <<<<<<<<<<<<<<
 *             'mean_tlen_pp': mean_tlen_pp,
 *             'rms_tlen': rms_tlen,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__mean_tlen), __pyx_v_mean_tlen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":832
 * #            'reads_pp': reads_pp,
 *             'mean_tlen': mean_tlen,
 *             'mean_tlen_pp': mean_tlen_pp,             # <<<<<<<<<<<<<<
 *             'rms_tlen': rms_tlen,
 *             'rms_tlen_pp': rms_tlen_pp,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__mean_tlen_pp), __pyx_v_mean_tlen_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":833
 *             'mean_tlen': mean_tlen,
 *             'mean_tlen_pp': mean_tlen_pp,
 *             'rms_tlen': rms_tlen,             # <<<<<<<<<<<<<<
 *             'rms_tlen_pp': rms_tlen_pp,
 *             'std_tlen': std_tlen,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_tlen), __pyx_v_rms_tlen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":834
 *             'mean_tlen_pp': mean_tlen_pp,
 *             'rms_tlen': rms_tlen,
 *             'rms_tlen_pp': rms_tlen_pp,             # <<<<<<<<<<<<<<
 *             'std_tlen': std_tlen,
 *             'std_tlen_pp': std_tlen_pp}
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_tlen_pp), __pyx_v_rms_tlen_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":835
 *             'rms_tlen': rms_tlen,
 *             'rms_tlen_pp': rms_tlen_pp,
 *             'std_tlen': std_tlen,             # <<<<<<<<<<<<<<
 *             'std_tlen_pp': std_tlen_pp}
 * 
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__std_tlen), __pyx_v_std_tlen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":836
 *             'rms_tlen_pp': rms_tlen_pp,
 *             'std_tlen': std_tlen,
 *             'std_tlen_pp': std_tlen_pp}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__std_tlen_pp), __pyx_v_std_tlen_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_mean_tlen);
  __Pyx_XDECREF(__pyx_v_rms_tlen);
  __Pyx_XDECREF(__pyx_v_std_tlen);
  __Pyx_XDECREF(__pyx_v_mean_tlen_pp);
  __Pyx_XDECREF(__pyx_v_rms_tlen_pp);
  __Pyx_XDECREF(__pyx_v_std_tlen_pp);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_43construct_rec_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_43construct_rec_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_tlen (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__col,&__pyx_n_s__one_based,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__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_tlen", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_tlen") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[1]);
    if (values[2]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 725; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":725
 * 
 * cpdef object construct_rec_tlen(Samfile samfile, PileupProxy col,
 *                                 bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_tlen", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_42construct_rec_tlen(__pyx_self, __pyx_v_samfile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":724
 * 
 * 
 * cpdef object construct_rec_tlen(Samfile samfile, PileupProxy col,             # <<<<<<<<<<<<<<
 *                                 bint one_based=False):
 * 
 */

static PyObject *__pyx_pf_10pysamstats_42construct_rec_tlen(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_tlen __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_tlen", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_tlen(__pyx_v_samfile, __pyx_v_col, 0, &__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_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_46generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_45stat_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_45stat_tlen = {__Pyx_NAMESTR("stat_tlen"), (PyCFunction)__pyx_pw_10pysamstats_45stat_tlen, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_45stat_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_tlen (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__samfile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysamstats.pyx":839
 * 
 * 
 * def stat_tlen(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_26;
    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__chrom);
          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__one_based);
          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, "stat_tlen") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
    __pyx_v_one_based = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_tlen", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_44stat_tlen(__pyx_self, __pyx_v_samfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_44stat_tlen(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_tlen", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *)__pyx_ptype_10pysamstats___pyx_scope_struct_6_stat_tlen->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_6_stat_tlen, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_46generator6, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_46generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_tlen __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":840
 * 
 * def stat_tlen(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_tlen(samfile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":841
 * def stat_tlen(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_tlen(samfile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 841; __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 = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 841; __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 = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":842
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_tlen(samfile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_tlen(__pyx_cur_scope->__pyx_v_samfile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_tlen", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_48write_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_48write_tlen = {__Pyx_NAMESTR("write_tlen"), (PyCFunction)__pyx_pw_10pysamstats_48write_tlen, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_48write_tlen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_tlen (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_tlen", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_47write_tlen(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":845
 * 
 * 
 * def write_tlen(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *  #                 'reads_all', 'reads_paired', 'reads_pp',
 */

static PyObject *__pyx_pf_10pysamstats_47write_tlen(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_tlen", 0);

  /* "pysamstats.pyx":846
 * 
 * def write_tlen(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *  #                 'reads_all', 'reads_paired', 'reads_pp',
 *                   'mean_tlen', 'mean_tlen_pp',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_27));
  __pyx_v_fieldnames = __pyx_k_tuple_27;

  /* "pysamstats.pyx":851
 *                   'rms_tlen', 'rms_tlen_pp',
 *                   'std_tlen', 'std_tlen_pp')
 *     write_stats(stat_tlen, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_tlen); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __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 = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_tlen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":859
 * 
 * 
 * cpdef object construct_rec_tlen_strand(Samfile samfile, PileupProxy col,             # <<<<<<<<<<<<<<
 *                                        bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_50construct_rec_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_tlen_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_tlen_strand *__pyx_optional_args) {

  /* "pysamstats.pyx":860
 * 
 * cpdef object construct_rec_tlen_strand(Samfile samfile, PileupProxy col,
 *                                        bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_mate_other_chr;
  unsigned int __pyx_v_reads_fwd;
  unsigned int __pyx_v_reads_rev;
  unsigned int __pyx_v_reads_p;
  unsigned int __pyx_v_reads_p_fwd;
  unsigned int __pyx_v_reads_p_rev;
  unsigned int __pyx_v_reads_pp;
  unsigned int __pyx_v_reads_pp_fwd;
  unsigned int __pyx_v_reads_pp_rev;
  int64_t __pyx_v_tlen;
  int64_t __pyx_v_tlen_squared;
  int64_t __pyx_v_tlen_p_sum;
  double __pyx_v_tlen_p_mean;
  double __pyx_v_tlen_p_dev_squared;
  double __pyx_v_tlen_p_dev_squared_sum;
  int64_t __pyx_v_tlen_p_squared_sum;
  int64_t __pyx_v_tlen_p_fwd_sum;
  double __pyx_v_tlen_p_fwd_mean;
  double __pyx_v_tlen_p_fwd_dev_squared;
  double __pyx_v_tlen_p_fwd_dev_squared_sum;
  int64_t __pyx_v_tlen_p_fwd_squared_sum;
  int64_t __pyx_v_tlen_p_rev_sum;
  double __pyx_v_tlen_p_rev_mean;
  double __pyx_v_tlen_p_rev_dev_squared;
  double __pyx_v_tlen_p_rev_dev_squared_sum;
  int64_t __pyx_v_tlen_p_rev_squared_sum;
  int64_t __pyx_v_tlen_pp_sum;
  double __pyx_v_tlen_pp_mean;
  double __pyx_v_tlen_pp_dev_squared;
  double __pyx_v_tlen_pp_dev_squared_sum;
  int64_t __pyx_v_tlen_pp_squared_sum;
  int64_t __pyx_v_tlen_pp_fwd_sum;
  double __pyx_v_tlen_pp_fwd_mean;
  double __pyx_v_tlen_pp_fwd_dev_squared;
  double __pyx_v_tlen_pp_fwd_dev_squared_sum;
  int64_t __pyx_v_tlen_pp_fwd_squared_sum;
  int64_t __pyx_v_tlen_pp_rev_sum;
  double __pyx_v_tlen_pp_rev_mean;
  double __pyx_v_tlen_pp_rev_dev_squared;
  double __pyx_v_tlen_pp_rev_dev_squared_sum;
  int64_t __pyx_v_tlen_pp_rev_squared_sum;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  int __pyx_v_is_reverse;
  int __pyx_v_mate_is_unmapped;
  PyObject *__pyx_v_mean_tlen = NULL;
  PyObject *__pyx_v_rms_tlen = NULL;
  double __pyx_v_variance_tlen;
  PyObject *__pyx_v_std_tlen = NULL;
  PyObject *__pyx_v_mean_tlen_rev = NULL;
  PyObject *__pyx_v_rms_tlen_rev = NULL;
  double __pyx_v_variance_tlen_rev;
  PyObject *__pyx_v_std_tlen_rev = NULL;
  PyObject *__pyx_v_mean_tlen_fwd = NULL;
  PyObject *__pyx_v_rms_tlen_fwd = NULL;
  double __pyx_v_variance_tlen_fwd;
  PyObject *__pyx_v_std_tlen_fwd = NULL;
  PyObject *__pyx_v_mean_tlen_pp = NULL;
  PyObject *__pyx_v_rms_tlen_pp = NULL;
  double __pyx_v_variance_tlen_pp;
  PyObject *__pyx_v_std_tlen_pp = NULL;
  PyObject *__pyx_v_mean_tlen_pp_rev = NULL;
  PyObject *__pyx_v_rms_tlen_pp_rev = NULL;
  double __pyx_v_variance_tlen_pp_rev;
  PyObject *__pyx_v_std_tlen_pp_rev = NULL;
  PyObject *__pyx_v_mean_tlen_pp_fwd = NULL;
  PyObject *__pyx_v_rms_tlen_pp_fwd = NULL;
  double __pyx_v_variance_tlen_pp_fwd;
  PyObject *__pyx_v_std_tlen_pp_fwd = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int32_t __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  double __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_tlen_strand", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":874
 * 
 *     # counting variables
 *     cdef unsigned int reads_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_p = 0 # reads "paired", i.e., mate is mapped to same chromosome, so tlen is meaningful
 */
  __pyx_v_reads_fwd = 0;

  /* "pysamstats.pyx":875
 *     # counting variables
 *     cdef unsigned int reads_fwd = 0
 *     cdef unsigned int reads_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_p = 0 # reads "paired", i.e., mate is mapped to same chromosome, so tlen is meaningful
 *     cdef unsigned int reads_p_fwd = 0
 */
  __pyx_v_reads_rev = 0;

  /* "pysamstats.pyx":876
 *     cdef unsigned int reads_fwd = 0
 *     cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_p = 0 # reads "paired", i.e., mate is mapped to same chromosome, so tlen is meaningful             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_p_fwd = 0
 *     cdef unsigned int reads_p_rev = 0
 */
  __pyx_v_reads_p = 0;

  /* "pysamstats.pyx":877
 *     cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_p = 0 # reads "paired", i.e., mate is mapped to same chromosome, so tlen is meaningful
 *     cdef unsigned int reads_p_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_p_rev = 0
 *     cdef unsigned int reads_pp = 0 # reads "properly paired", as defined by aligner
 */
  __pyx_v_reads_p_fwd = 0;

  /* "pysamstats.pyx":878
 *     cdef unsigned int reads_p = 0 # reads "paired", i.e., mate is mapped to same chromosome, so tlen is meaningful
 *     cdef unsigned int reads_p_fwd = 0
 *     cdef unsigned int reads_p_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp = 0 # reads "properly paired", as defined by aligner
 *     cdef unsigned int reads_pp_fwd = 0
 */
  __pyx_v_reads_p_rev = 0;

  /* "pysamstats.pyx":879
 *     cdef unsigned int reads_p_fwd = 0
 *     cdef unsigned int reads_p_rev = 0
 *     cdef unsigned int reads_pp = 0 # reads "properly paired", as defined by aligner             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_pp_rev = 0
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":880
 *     cdef unsigned int reads_p_rev = 0
 *     cdef unsigned int reads_pp = 0 # reads "properly paired", as defined by aligner
 *     cdef unsigned int reads_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_rev = 0
 * 
 */
  __pyx_v_reads_pp_fwd = 0;

  /* "pysamstats.pyx":881
 *     cdef unsigned int reads_pp = 0 # reads "properly paired", as defined by aligner
 *     cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_pp_rev = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int64_t tlen
 */
  __pyx_v_reads_pp_rev = 0;

  /* "pysamstats.pyx":886
 *     cdef int64_t tlen_squared
 * 
 *     cdef int64_t tlen_p_sum = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_p_mean = 0
 *     cdef double tlen_p_dev_squared
 */
  __pyx_v_tlen_p_sum = 0;

  /* "pysamstats.pyx":887
 * 
 *     cdef int64_t tlen_p_sum = 0
 *     cdef double tlen_p_mean = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_p_dev_squared
 *     cdef double tlen_p_dev_squared_sum = 0
 */
  __pyx_v_tlen_p_mean = 0.0;

  /* "pysamstats.pyx":889
 *     cdef double tlen_p_mean = 0
 *     cdef double tlen_p_dev_squared
 *     cdef double tlen_p_dev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_p_squared_sum = 0
 *     cdef int64_t tlen_p_fwd_sum = 0
 */
  __pyx_v_tlen_p_dev_squared_sum = 0.0;

  /* "pysamstats.pyx":890
 *     cdef double tlen_p_dev_squared
 *     cdef double tlen_p_dev_squared_sum = 0
 *     cdef int64_t tlen_p_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_p_fwd_sum = 0
 *     cdef double tlen_p_fwd_mean = 0
 */
  __pyx_v_tlen_p_squared_sum = 0;

  /* "pysamstats.pyx":891
 *     cdef double tlen_p_dev_squared_sum = 0
 *     cdef int64_t tlen_p_squared_sum = 0
 *     cdef int64_t tlen_p_fwd_sum = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_p_fwd_mean = 0
 *     cdef double tlen_p_fwd_dev_squared
 */
  __pyx_v_tlen_p_fwd_sum = 0;

  /* "pysamstats.pyx":892
 *     cdef int64_t tlen_p_squared_sum = 0
 *     cdef int64_t tlen_p_fwd_sum = 0
 *     cdef double tlen_p_fwd_mean = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_p_fwd_dev_squared
 *     cdef double tlen_p_fwd_dev_squared_sum = 0
 */
  __pyx_v_tlen_p_fwd_mean = 0.0;

  /* "pysamstats.pyx":894
 *     cdef double tlen_p_fwd_mean = 0
 *     cdef double tlen_p_fwd_dev_squared
 *     cdef double tlen_p_fwd_dev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_p_fwd_squared_sum = 0
 *     cdef int64_t tlen_p_rev_sum = 0
 */
  __pyx_v_tlen_p_fwd_dev_squared_sum = 0.0;

  /* "pysamstats.pyx":895
 *     cdef double tlen_p_fwd_dev_squared
 *     cdef double tlen_p_fwd_dev_squared_sum = 0
 *     cdef int64_t tlen_p_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_p_rev_sum = 0
 *     cdef double tlen_p_rev_mean = 0
 */
  __pyx_v_tlen_p_fwd_squared_sum = 0;

  /* "pysamstats.pyx":896
 *     cdef double tlen_p_fwd_dev_squared_sum = 0
 *     cdef int64_t tlen_p_fwd_squared_sum = 0
 *     cdef int64_t tlen_p_rev_sum = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_p_rev_mean = 0
 *     cdef double tlen_p_rev_dev_squared
 */
  __pyx_v_tlen_p_rev_sum = 0;

  /* "pysamstats.pyx":897
 *     cdef int64_t tlen_p_fwd_squared_sum = 0
 *     cdef int64_t tlen_p_rev_sum = 0
 *     cdef double tlen_p_rev_mean = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_p_rev_dev_squared
 *     cdef double tlen_p_rev_dev_squared_sum = 0
 */
  __pyx_v_tlen_p_rev_mean = 0.0;

  /* "pysamstats.pyx":899
 *     cdef double tlen_p_rev_mean = 0
 *     cdef double tlen_p_rev_dev_squared
 *     cdef double tlen_p_rev_dev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_p_rev_squared_sum = 0
 * 
 */
  __pyx_v_tlen_p_rev_dev_squared_sum = 0.0;

  /* "pysamstats.pyx":900
 *     cdef double tlen_p_rev_dev_squared
 *     cdef double tlen_p_rev_dev_squared_sum = 0
 *     cdef int64_t tlen_p_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef int64_t tlen_pp_sum = 0
 */
  __pyx_v_tlen_p_rev_squared_sum = 0;

  /* "pysamstats.pyx":902
 *     cdef int64_t tlen_p_rev_squared_sum = 0
 * 
 *     cdef int64_t tlen_pp_sum = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_pp_mean = 0
 *     cdef double tlen_pp_dev_squared
 */
  __pyx_v_tlen_pp_sum = 0;

  /* "pysamstats.pyx":903
 * 
 *     cdef int64_t tlen_pp_sum = 0
 *     cdef double tlen_pp_mean = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_pp_dev_squared
 *     cdef double tlen_pp_dev_squared_sum = 0
 */
  __pyx_v_tlen_pp_mean = 0.0;

  /* "pysamstats.pyx":905
 *     cdef double tlen_pp_mean = 0
 *     cdef double tlen_pp_dev_squared
 *     cdef double tlen_pp_dev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_pp_squared_sum = 0
 *     cdef int64_t tlen_pp_fwd_sum = 0
 */
  __pyx_v_tlen_pp_dev_squared_sum = 0.0;

  /* "pysamstats.pyx":906
 *     cdef double tlen_pp_dev_squared
 *     cdef double tlen_pp_dev_squared_sum = 0
 *     cdef int64_t tlen_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_pp_fwd_sum = 0
 *     cdef double tlen_pp_fwd_mean = 0
 */
  __pyx_v_tlen_pp_squared_sum = 0;

  /* "pysamstats.pyx":907
 *     cdef double tlen_pp_dev_squared_sum = 0
 *     cdef int64_t tlen_pp_squared_sum = 0
 *     cdef int64_t tlen_pp_fwd_sum = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_pp_fwd_mean = 0
 *     cdef double tlen_pp_fwd_dev_squared
 */
  __pyx_v_tlen_pp_fwd_sum = 0;

  /* "pysamstats.pyx":908
 *     cdef int64_t tlen_pp_squared_sum = 0
 *     cdef int64_t tlen_pp_fwd_sum = 0
 *     cdef double tlen_pp_fwd_mean = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_pp_fwd_dev_squared
 *     cdef double tlen_pp_fwd_dev_squared_sum = 0
 */
  __pyx_v_tlen_pp_fwd_mean = 0.0;

  /* "pysamstats.pyx":910
 *     cdef double tlen_pp_fwd_mean = 0
 *     cdef double tlen_pp_fwd_dev_squared
 *     cdef double tlen_pp_fwd_dev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_pp_fwd_squared_sum = 0
 *     cdef int64_t tlen_pp_rev_sum = 0
 */
  __pyx_v_tlen_pp_fwd_dev_squared_sum = 0.0;

  /* "pysamstats.pyx":911
 *     cdef double tlen_pp_fwd_dev_squared
 *     cdef double tlen_pp_fwd_dev_squared_sum = 0
 *     cdef int64_t tlen_pp_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_pp_rev_sum = 0
 *     cdef double tlen_pp_rev_mean = 0
 */
  __pyx_v_tlen_pp_fwd_squared_sum = 0;

  /* "pysamstats.pyx":912
 *     cdef double tlen_pp_fwd_dev_squared_sum = 0
 *     cdef int64_t tlen_pp_fwd_squared_sum = 0
 *     cdef int64_t tlen_pp_rev_sum = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_pp_rev_mean = 0
 *     cdef double tlen_pp_rev_dev_squared
 */
  __pyx_v_tlen_pp_rev_sum = 0;

  /* "pysamstats.pyx":913
 *     cdef int64_t tlen_pp_fwd_squared_sum = 0
 *     cdef int64_t tlen_pp_rev_sum = 0
 *     cdef double tlen_pp_rev_mean = 0             # <<<<<<<<<<<<<<
 *     cdef double tlen_pp_rev_dev_squared
 *     cdef double tlen_pp_rev_dev_squared_sum = 0
 */
  __pyx_v_tlen_pp_rev_mean = 0.0;

  /* "pysamstats.pyx":915
 *     cdef double tlen_pp_rev_mean = 0
 *     cdef double tlen_pp_rev_dev_squared
 *     cdef double tlen_pp_rev_dev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef int64_t tlen_pp_rev_squared_sum = 0
 * 
 */
  __pyx_v_tlen_pp_rev_dev_squared_sum = 0.0;

  /* "pysamstats.pyx":916
 *     cdef double tlen_pp_rev_dev_squared
 *     cdef double tlen_pp_rev_dev_squared_sum = 0
 *     cdef int64_t tlen_pp_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_tlen_pp_rev_squared_sum = 0;

  /* "pysamstats.pyx":919
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 919; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":920
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":923
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":924
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":927
 * 
 *     # loop over reads
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":928
 *     # loop over reads
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":929
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 * 
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":930
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 * 
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":932
 *         flag = aln.core.flag
 * 
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":933
 * 
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)             # <<<<<<<<<<<<<<
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)
 */
    __pyx_v_is_reverse = ((int)(__pyx_v_flag & 16));

    /* "pysamstats.pyx":934
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)             # <<<<<<<<<<<<<<
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)
 * 
 */
    __pyx_v_mate_is_unmapped = ((int)(__pyx_v_flag & 8));

    /* "pysamstats.pyx":935
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)             # <<<<<<<<<<<<<<
 * 
 *         # not sure these are really needed
 */
    __pyx_v_mate_other_chr = ((int)(__pyx_v_aln->core.tid != __pyx_v_aln->core.mtid));

    /* "pysamstats.pyx":938
 * 
 *         # not sure these are really needed
 *         if is_reverse:             # <<<<<<<<<<<<<<
 *             reads_rev += 1
 *         else:
 */
    if (__pyx_v_is_reverse) {

      /* "pysamstats.pyx":939
 *         # not sure these are really needed
 *         if is_reverse:
 *             reads_rev += 1             # <<<<<<<<<<<<<<
 *         else:
 *             reads_fwd += 1
 */
      __pyx_v_reads_rev = (__pyx_v_reads_rev + 1);
      goto __pyx_L5;
    }
    /*else*/ {

      /* "pysamstats.pyx":941
 *             reads_rev += 1
 *         else:
 *             reads_fwd += 1             # <<<<<<<<<<<<<<
 * 
 *         # N.B., pysam exposes this property as 'tlen' rather than 'isize' so we
 */
      __pyx_v_reads_fwd = (__pyx_v_reads_fwd + 1);
    }
    __pyx_L5:;

    /* "pysamstats.pyx":945
 *         # N.B., pysam exposes this property as 'tlen' rather than 'isize' so we
 *         # follow their naming convention
 *         tlen = aln.core.isize             # <<<<<<<<<<<<<<
 *         tlen_squared = tlen**2
 * 
 */
    __pyx_t_10 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_10;

    /* "pysamstats.pyx":946
 *         # follow their naming convention
 *         tlen = aln.core.isize
 *         tlen_squared = tlen**2             # <<<<<<<<<<<<<<
 * 
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 */
    __pyx_v_tlen_squared = __Pyx_pow_long(((long)__pyx_v_tlen), 2);

    /* "pysamstats.pyx":949
 * 
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 *         if not mate_is_unmapped and not mate_other_chr:             # <<<<<<<<<<<<<<
 *             reads_p += 1
 *             tlen_p_sum += tlen
 */
    __pyx_t_11 = (!__pyx_v_mate_is_unmapped);
    if (__pyx_t_11) {
      __pyx_t_12 = (!__pyx_v_mate_other_chr);
      __pyx_t_13 = __pyx_t_12;
    } else {
      __pyx_t_13 = __pyx_t_11;
    }
    if (__pyx_t_13) {

      /* "pysamstats.pyx":950
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 *         if not mate_is_unmapped and not mate_other_chr:
 *             reads_p += 1             # <<<<<<<<<<<<<<
 *             tlen_p_sum += tlen
 *             tlen_p_squared_sum += tlen_squared
 */
      __pyx_v_reads_p = (__pyx_v_reads_p + 1);

      /* "pysamstats.pyx":951
 *         if not mate_is_unmapped and not mate_other_chr:
 *             reads_p += 1
 *             tlen_p_sum += tlen             # <<<<<<<<<<<<<<
 *             tlen_p_squared_sum += tlen_squared
 *             if is_reverse:
 */
      __pyx_v_tlen_p_sum = (__pyx_v_tlen_p_sum + __pyx_v_tlen);

      /* "pysamstats.pyx":952
 *             reads_p += 1
 *             tlen_p_sum += tlen
 *             tlen_p_squared_sum += tlen_squared             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_p_rev += 1
 */
      __pyx_v_tlen_p_squared_sum = (__pyx_v_tlen_p_squared_sum + __pyx_v_tlen_squared);

      /* "pysamstats.pyx":953
 *             tlen_p_sum += tlen
 *             tlen_p_squared_sum += tlen_squared
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_p_rev += 1
 *                 tlen_p_rev_sum += tlen
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":954
 *             tlen_p_squared_sum += tlen_squared
 *             if is_reverse:
 *                 reads_p_rev += 1             # <<<<<<<<<<<<<<
 *                 tlen_p_rev_sum += tlen
 *                 tlen_p_rev_squared_sum += tlen_squared
 */
        __pyx_v_reads_p_rev = (__pyx_v_reads_p_rev + 1);

        /* "pysamstats.pyx":955
 *             if is_reverse:
 *                 reads_p_rev += 1
 *                 tlen_p_rev_sum += tlen             # <<<<<<<<<<<<<<
 *                 tlen_p_rev_squared_sum += tlen_squared
 *             else:
 */
        __pyx_v_tlen_p_rev_sum = (__pyx_v_tlen_p_rev_sum + __pyx_v_tlen);

        /* "pysamstats.pyx":956
 *                 reads_p_rev += 1
 *                 tlen_p_rev_sum += tlen
 *                 tlen_p_rev_squared_sum += tlen_squared             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_p_fwd += 1
 */
        __pyx_v_tlen_p_rev_squared_sum = (__pyx_v_tlen_p_rev_squared_sum + __pyx_v_tlen_squared);
        goto __pyx_L7;
      }
      /*else*/ {

        /* "pysamstats.pyx":958
 *                 tlen_p_rev_squared_sum += tlen_squared
 *             else:
 *                 reads_p_fwd += 1             # <<<<<<<<<<<<<<
 *                 tlen_p_fwd_sum += tlen
 *                 tlen_p_fwd_squared_sum += tlen_squared
 */
        __pyx_v_reads_p_fwd = (__pyx_v_reads_p_fwd + 1);

        /* "pysamstats.pyx":959
 *             else:
 *                 reads_p_fwd += 1
 *                 tlen_p_fwd_sum += tlen             # <<<<<<<<<<<<<<
 *                 tlen_p_fwd_squared_sum += tlen_squared
 * 
 */
        __pyx_v_tlen_p_fwd_sum = (__pyx_v_tlen_p_fwd_sum + __pyx_v_tlen);

        /* "pysamstats.pyx":960
 *                 reads_p_fwd += 1
 *                 tlen_p_fwd_sum += tlen
 *                 tlen_p_fwd_squared_sum += tlen_squared             # <<<<<<<<<<<<<<
 * 
 *             if is_proper_pair:
 */
        __pyx_v_tlen_p_fwd_squared_sum = (__pyx_v_tlen_p_fwd_squared_sum + __pyx_v_tlen_squared);
      }
      __pyx_L7:;

      /* "pysamstats.pyx":962
 *                 tlen_p_fwd_squared_sum += tlen_squared
 * 
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp += 1
 *                 tlen_pp_sum += tlen
 */
      if (__pyx_v_is_proper_pair) {

        /* "pysamstats.pyx":963
 * 
 *             if is_proper_pair:
 *                 reads_pp += 1             # <<<<<<<<<<<<<<
 *                 tlen_pp_sum += tlen
 *                 tlen_pp_squared_sum += tlen_squared
 */
        __pyx_v_reads_pp = (__pyx_v_reads_pp + 1);

        /* "pysamstats.pyx":964
 *             if is_proper_pair:
 *                 reads_pp += 1
 *                 tlen_pp_sum += tlen             # <<<<<<<<<<<<<<
 *                 tlen_pp_squared_sum += tlen_squared
 *                 if is_reverse:
 */
        __pyx_v_tlen_pp_sum = (__pyx_v_tlen_pp_sum + __pyx_v_tlen);

        /* "pysamstats.pyx":965
 *                 reads_pp += 1
 *                 tlen_pp_sum += tlen
 *                 tlen_pp_squared_sum += tlen_squared             # <<<<<<<<<<<<<<
 *                 if is_reverse:
 *                     reads_pp_rev += 1
 */
        __pyx_v_tlen_pp_squared_sum = (__pyx_v_tlen_pp_squared_sum + __pyx_v_tlen_squared);

        /* "pysamstats.pyx":966
 *                 tlen_pp_sum += tlen
 *                 tlen_pp_squared_sum += tlen_squared
 *                 if is_reverse:             # <<<<<<<<<<<<<<
 *                     reads_pp_rev += 1
 *                     tlen_pp_rev_sum += tlen
 */
        if (__pyx_v_is_reverse) {

          /* "pysamstats.pyx":967
 *                 tlen_pp_squared_sum += tlen_squared
 *                 if is_reverse:
 *                     reads_pp_rev += 1             # <<<<<<<<<<<<<<
 *                     tlen_pp_rev_sum += tlen
 *                     tlen_pp_rev_squared_sum += tlen_squared
 */
          __pyx_v_reads_pp_rev = (__pyx_v_reads_pp_rev + 1);

          /* "pysamstats.pyx":968
 *                 if is_reverse:
 *                     reads_pp_rev += 1
 *                     tlen_pp_rev_sum += tlen             # <<<<<<<<<<<<<<
 *                     tlen_pp_rev_squared_sum += tlen_squared
 *                 else:
 */
          __pyx_v_tlen_pp_rev_sum = (__pyx_v_tlen_pp_rev_sum + __pyx_v_tlen);

          /* "pysamstats.pyx":969
 *                     reads_pp_rev += 1
 *                     tlen_pp_rev_sum += tlen
 *                     tlen_pp_rev_squared_sum += tlen_squared             # <<<<<<<<<<<<<<
 *                 else:
 *                     reads_pp_fwd += 1
 */
          __pyx_v_tlen_pp_rev_squared_sum = (__pyx_v_tlen_pp_rev_squared_sum + __pyx_v_tlen_squared);
          goto __pyx_L9;
        }
        /*else*/ {

          /* "pysamstats.pyx":971
 *                     tlen_pp_rev_squared_sum += tlen_squared
 *                 else:
 *                     reads_pp_fwd += 1             # <<<<<<<<<<<<<<
 *                     tlen_pp_fwd_sum += tlen
 *                     tlen_pp_fwd_squared_sum += tlen_squared
 */
          __pyx_v_reads_pp_fwd = (__pyx_v_reads_pp_fwd + 1);

          /* "pysamstats.pyx":972
 *                 else:
 *                     reads_pp_fwd += 1
 *                     tlen_pp_fwd_sum += tlen             # <<<<<<<<<<<<<<
 *                     tlen_pp_fwd_squared_sum += tlen_squared
 * 
 */
          __pyx_v_tlen_pp_fwd_sum = (__pyx_v_tlen_pp_fwd_sum + __pyx_v_tlen);

          /* "pysamstats.pyx":973
 *                     reads_pp_fwd += 1
 *                     tlen_pp_fwd_sum += tlen
 *                     tlen_pp_fwd_squared_sum += tlen_squared             # <<<<<<<<<<<<<<
 * 
 *     # calculate intermediate variables
 */
          __pyx_v_tlen_pp_fwd_squared_sum = (__pyx_v_tlen_pp_fwd_squared_sum + __pyx_v_tlen_squared);
        }
        __pyx_L9:;
        goto __pyx_L8;
      }
      __pyx_L8:;
      goto __pyx_L6;
    }
    __pyx_L6:;
  }

  /* "pysamstats.pyx":976
 * 
 *     # calculate intermediate variables
 *     if reads_p > 0:             # <<<<<<<<<<<<<<
 *         tlen_p_mean = tlen_p_sum * 1. / reads_p
 *         if reads_p_rev > 0:
 */
  __pyx_t_13 = (__pyx_v_reads_p > 0);
  if (__pyx_t_13) {

    /* "pysamstats.pyx":977
 *     # calculate intermediate variables
 *     if reads_p > 0:
 *         tlen_p_mean = tlen_p_sum * 1. / reads_p             # <<<<<<<<<<<<<<
 *         if reads_p_rev > 0:
 *             tlen_p_rev_mean = tlen_p_rev_sum * 1. / reads_p_rev
 */
    __pyx_t_14 = (__pyx_v_tlen_p_sum * 1.);
    if (unlikely(__pyx_v_reads_p == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_tlen_p_mean = (__pyx_t_14 / __pyx_v_reads_p);

    /* "pysamstats.pyx":978
 *     if reads_p > 0:
 *         tlen_p_mean = tlen_p_sum * 1. / reads_p
 *         if reads_p_rev > 0:             # <<<<<<<<<<<<<<
 *             tlen_p_rev_mean = tlen_p_rev_sum * 1. / reads_p_rev
 *         if reads_p_fwd > 0:
 */
    __pyx_t_13 = (__pyx_v_reads_p_rev > 0);
    if (__pyx_t_13) {

      /* "pysamstats.pyx":979
 *         tlen_p_mean = tlen_p_sum * 1. / reads_p
 *         if reads_p_rev > 0:
 *             tlen_p_rev_mean = tlen_p_rev_sum * 1. / reads_p_rev             # <<<<<<<<<<<<<<
 *         if reads_p_fwd > 0:
 *             tlen_p_fwd_mean = tlen_p_fwd_sum * 1. / reads_p_fwd
 */
      __pyx_t_14 = (__pyx_v_tlen_p_rev_sum * 1.);
      if (unlikely(__pyx_v_reads_p_rev == 0)) {
        PyErr_Format(PyExc_ZeroDivisionError, "float division");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_v_tlen_p_rev_mean = (__pyx_t_14 / __pyx_v_reads_p_rev);
      goto __pyx_L11;
    }
    __pyx_L11:;

    /* "pysamstats.pyx":980
 *         if reads_p_rev > 0:
 *             tlen_p_rev_mean = tlen_p_rev_sum * 1. / reads_p_rev
 *         if reads_p_fwd > 0:             # <<<<<<<<<<<<<<
 *             tlen_p_fwd_mean = tlen_p_fwd_sum * 1. / reads_p_fwd
 *     if reads_pp > 0:
 */
    __pyx_t_13 = (__pyx_v_reads_p_fwd > 0);
    if (__pyx_t_13) {

      /* "pysamstats.pyx":981
 *             tlen_p_rev_mean = tlen_p_rev_sum * 1. / reads_p_rev
 *         if reads_p_fwd > 0:
 *             tlen_p_fwd_mean = tlen_p_fwd_sum * 1. / reads_p_fwd             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         tlen_pp_mean = tlen_pp_sum * 1. / reads_pp
 */
      __pyx_t_14 = (__pyx_v_tlen_p_fwd_sum * 1.);
      if (unlikely(__pyx_v_reads_p_fwd == 0)) {
        PyErr_Format(PyExc_ZeroDivisionError, "float division");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_v_tlen_p_fwd_mean = (__pyx_t_14 / __pyx_v_reads_p_fwd);
      goto __pyx_L12;
    }
    __pyx_L12:;
    goto __pyx_L10;
  }
  __pyx_L10:;

  /* "pysamstats.pyx":982
 *         if reads_p_fwd > 0:
 *             tlen_p_fwd_mean = tlen_p_fwd_sum * 1. / reads_p_fwd
 *     if reads_pp > 0:             # <<<<<<<<<<<<<<
 *         tlen_pp_mean = tlen_pp_sum * 1. / reads_pp
 *         if reads_pp_rev > 0:
 */
  __pyx_t_13 = (__pyx_v_reads_pp > 0);
  if (__pyx_t_13) {

    /* "pysamstats.pyx":983
 *             tlen_p_fwd_mean = tlen_p_fwd_sum * 1. / reads_p_fwd
 *     if reads_pp > 0:
 *         tlen_pp_mean = tlen_pp_sum * 1. / reads_pp             # <<<<<<<<<<<<<<
 *         if reads_pp_rev > 0:
 *             tlen_pp_rev_mean = tlen_pp_rev_sum * 1. / reads_pp_rev
 */
    __pyx_t_14 = (__pyx_v_tlen_pp_sum * 1.);
    if (unlikely(__pyx_v_reads_pp == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 983; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_tlen_pp_mean = (__pyx_t_14 / __pyx_v_reads_pp);

    /* "pysamstats.pyx":984
 *     if reads_pp > 0:
 *         tlen_pp_mean = tlen_pp_sum * 1. / reads_pp
 *         if reads_pp_rev > 0:             # <<<<<<<<<<<<<<
 *             tlen_pp_rev_mean = tlen_pp_rev_sum * 1. / reads_pp_rev
 *         if reads_pp_fwd > 0:
 */
    __pyx_t_13 = (__pyx_v_reads_pp_rev > 0);
    if (__pyx_t_13) {

      /* "pysamstats.pyx":985
 *         tlen_pp_mean = tlen_pp_sum * 1. / reads_pp
 *         if reads_pp_rev > 0:
 *             tlen_pp_rev_mean = tlen_pp_rev_sum * 1. / reads_pp_rev             # <<<<<<<<<<<<<<
 *         if reads_pp_fwd > 0:
 *             tlen_pp_fwd_mean = tlen_pp_fwd_sum * 1. / reads_pp_fwd
 */
      __pyx_t_14 = (__pyx_v_tlen_pp_rev_sum * 1.);
      if (unlikely(__pyx_v_reads_pp_rev == 0)) {
        PyErr_Format(PyExc_ZeroDivisionError, "float division");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_v_tlen_pp_rev_mean = (__pyx_t_14 / __pyx_v_reads_pp_rev);
      goto __pyx_L14;
    }
    __pyx_L14:;

    /* "pysamstats.pyx":986
 *         if reads_pp_rev > 0:
 *             tlen_pp_rev_mean = tlen_pp_rev_sum * 1. / reads_pp_rev
 *         if reads_pp_fwd > 0:             # <<<<<<<<<<<<<<
 *             tlen_pp_fwd_mean = tlen_pp_fwd_sum * 1. / reads_pp_fwd
 * 
 */
    __pyx_t_13 = (__pyx_v_reads_pp_fwd > 0);
    if (__pyx_t_13) {

      /* "pysamstats.pyx":987
 *             tlen_pp_rev_mean = tlen_pp_rev_sum * 1. / reads_pp_rev
 *         if reads_pp_fwd > 0:
 *             tlen_pp_fwd_mean = tlen_pp_fwd_sum * 1. / reads_pp_fwd             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads again to calculate variance (and hence std)
 */
      __pyx_t_14 = (__pyx_v_tlen_pp_fwd_sum * 1.);
      if (unlikely(__pyx_v_reads_pp_fwd == 0)) {
        PyErr_Format(PyExc_ZeroDivisionError, "float division");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 987; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_v_tlen_pp_fwd_mean = (__pyx_t_14 / __pyx_v_reads_pp_fwd);
      goto __pyx_L15;
    }
    __pyx_L15:;
    goto __pyx_L13;
  }
  __pyx_L13:;

  /* "pysamstats.pyx":990
 * 
 *     # loop over reads again to calculate variance (and hence std)
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":991
 *     # loop over reads again to calculate variance (and hence std)
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":992
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":993
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":994
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":995
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)             # <<<<<<<<<<<<<<
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)
 */
    __pyx_v_is_reverse = ((int)(__pyx_v_flag & 16));

    /* "pysamstats.pyx":996
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)             # <<<<<<<<<<<<<<
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)
 *         tlen = aln.core.isize
 */
    __pyx_v_mate_is_unmapped = ((int)(__pyx_v_flag & 8));

    /* "pysamstats.pyx":997
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)             # <<<<<<<<<<<<<<
 *         tlen = aln.core.isize
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 */
    __pyx_v_mate_other_chr = ((int)(__pyx_v_aln->core.tid != __pyx_v_aln->core.mtid));

    /* "pysamstats.pyx":998
 *         mate_is_unmapped = <bint>(flag & BAM_FMUNMAP)
 *         mate_other_chr = <bint>(aln.core.tid != aln.core.mtid)
 *         tlen = aln.core.isize             # <<<<<<<<<<<<<<
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 *         if not mate_is_unmapped and not mate_other_chr:
 */
    __pyx_t_10 = __pyx_v_aln->core.isize;
    __pyx_v_tlen = __pyx_t_10;

    /* "pysamstats.pyx":1000
 *         tlen = aln.core.isize
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 *         if not mate_is_unmapped and not mate_other_chr:             # <<<<<<<<<<<<<<
 *             tlen_p_dev_squared = (tlen - tlen_p_mean)**2
 *             tlen_p_dev_squared_sum += tlen_p_dev_squared
 */
    __pyx_t_13 = (!__pyx_v_mate_is_unmapped);
    if (__pyx_t_13) {
      __pyx_t_11 = (!__pyx_v_mate_other_chr);
      __pyx_t_12 = __pyx_t_11;
    } else {
      __pyx_t_12 = __pyx_t_13;
    }
    if (__pyx_t_12) {

      /* "pysamstats.pyx":1001
 *         # N.B. insert size is only meaningful if mate is mapped to same chromosome
 *         if not mate_is_unmapped and not mate_other_chr:
 *             tlen_p_dev_squared = (tlen - tlen_p_mean)**2             # <<<<<<<<<<<<<<
 *             tlen_p_dev_squared_sum += tlen_p_dev_squared
 *             if is_reverse:
 */
      __pyx_v_tlen_p_dev_squared = pow((__pyx_v_tlen - __pyx_v_tlen_p_mean), 2.0);

      /* "pysamstats.pyx":1002
 *         if not mate_is_unmapped and not mate_other_chr:
 *             tlen_p_dev_squared = (tlen - tlen_p_mean)**2
 *             tlen_p_dev_squared_sum += tlen_p_dev_squared             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 tlen_p_rev_dev_squared = (tlen - tlen_p_rev_mean)**2
 */
      __pyx_v_tlen_p_dev_squared_sum = (__pyx_v_tlen_p_dev_squared_sum + __pyx_v_tlen_p_dev_squared);

      /* "pysamstats.pyx":1003
 *             tlen_p_dev_squared = (tlen - tlen_p_mean)**2
 *             tlen_p_dev_squared_sum += tlen_p_dev_squared
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 tlen_p_rev_dev_squared = (tlen - tlen_p_rev_mean)**2
 *                 tlen_p_rev_dev_squared_sum += tlen_p_rev_dev_squared
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":1004
 *             tlen_p_dev_squared_sum += tlen_p_dev_squared
 *             if is_reverse:
 *                 tlen_p_rev_dev_squared = (tlen - tlen_p_rev_mean)**2             # <<<<<<<<<<<<<<
 *                 tlen_p_rev_dev_squared_sum += tlen_p_rev_dev_squared
 *             else:
 */
        __pyx_v_tlen_p_rev_dev_squared = pow((__pyx_v_tlen - __pyx_v_tlen_p_rev_mean), 2.0);

        /* "pysamstats.pyx":1005
 *             if is_reverse:
 *                 tlen_p_rev_dev_squared = (tlen - tlen_p_rev_mean)**2
 *                 tlen_p_rev_dev_squared_sum += tlen_p_rev_dev_squared             # <<<<<<<<<<<<<<
 *             else:
 *                 tlen_p_fwd_dev_squared = (tlen - tlen_p_fwd_mean)**2
 */
        __pyx_v_tlen_p_rev_dev_squared_sum = (__pyx_v_tlen_p_rev_dev_squared_sum + __pyx_v_tlen_p_rev_dev_squared);
        goto __pyx_L19;
      }
      /*else*/ {

        /* "pysamstats.pyx":1007
 *                 tlen_p_rev_dev_squared_sum += tlen_p_rev_dev_squared
 *             else:
 *                 tlen_p_fwd_dev_squared = (tlen - tlen_p_fwd_mean)**2             # <<<<<<<<<<<<<<
 *                 tlen_p_fwd_dev_squared_sum += tlen_p_fwd_dev_squared
 *             if is_proper_pair:
 */
        __pyx_v_tlen_p_fwd_dev_squared = pow((__pyx_v_tlen - __pyx_v_tlen_p_fwd_mean), 2.0);

        /* "pysamstats.pyx":1008
 *             else:
 *                 tlen_p_fwd_dev_squared = (tlen - tlen_p_fwd_mean)**2
 *                 tlen_p_fwd_dev_squared_sum += tlen_p_fwd_dev_squared             # <<<<<<<<<<<<<<
 *             if is_proper_pair:
 *                 tlen_pp_dev_squared = (tlen - tlen_pp_mean)**2
 */
        __pyx_v_tlen_p_fwd_dev_squared_sum = (__pyx_v_tlen_p_fwd_dev_squared_sum + __pyx_v_tlen_p_fwd_dev_squared);
      }
      __pyx_L19:;

      /* "pysamstats.pyx":1009
 *                 tlen_p_fwd_dev_squared = (tlen - tlen_p_fwd_mean)**2
 *                 tlen_p_fwd_dev_squared_sum += tlen_p_fwd_dev_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 tlen_pp_dev_squared = (tlen - tlen_pp_mean)**2
 *                 tlen_pp_dev_squared_sum += tlen_pp_dev_squared
 */
      if (__pyx_v_is_proper_pair) {

        /* "pysamstats.pyx":1010
 *                 tlen_p_fwd_dev_squared_sum += tlen_p_fwd_dev_squared
 *             if is_proper_pair:
 *                 tlen_pp_dev_squared = (tlen - tlen_pp_mean)**2             # <<<<<<<<<<<<<<
 *                 tlen_pp_dev_squared_sum += tlen_pp_dev_squared
 *                 if is_reverse:
 */
        __pyx_v_tlen_pp_dev_squared = pow((__pyx_v_tlen - __pyx_v_tlen_pp_mean), 2.0);

        /* "pysamstats.pyx":1011
 *             if is_proper_pair:
 *                 tlen_pp_dev_squared = (tlen - tlen_pp_mean)**2
 *                 tlen_pp_dev_squared_sum += tlen_pp_dev_squared             # <<<<<<<<<<<<<<
 *                 if is_reverse:
 *                     tlen_pp_rev_dev_squared = (tlen - tlen_pp_rev_mean)**2
 */
        __pyx_v_tlen_pp_dev_squared_sum = (__pyx_v_tlen_pp_dev_squared_sum + __pyx_v_tlen_pp_dev_squared);

        /* "pysamstats.pyx":1012
 *                 tlen_pp_dev_squared = (tlen - tlen_pp_mean)**2
 *                 tlen_pp_dev_squared_sum += tlen_pp_dev_squared
 *                 if is_reverse:             # <<<<<<<<<<<<<<
 *                     tlen_pp_rev_dev_squared = (tlen - tlen_pp_rev_mean)**2
 *                     tlen_pp_rev_dev_squared_sum += tlen_pp_rev_dev_squared
 */
        if (__pyx_v_is_reverse) {

          /* "pysamstats.pyx":1013
 *                 tlen_pp_dev_squared_sum += tlen_pp_dev_squared
 *                 if is_reverse:
 *                     tlen_pp_rev_dev_squared = (tlen - tlen_pp_rev_mean)**2             # <<<<<<<<<<<<<<
 *                     tlen_pp_rev_dev_squared_sum += tlen_pp_rev_dev_squared
 *                 else:
 */
          __pyx_v_tlen_pp_rev_dev_squared = pow((__pyx_v_tlen - __pyx_v_tlen_pp_rev_mean), 2.0);

          /* "pysamstats.pyx":1014
 *                 if is_reverse:
 *                     tlen_pp_rev_dev_squared = (tlen - tlen_pp_rev_mean)**2
 *                     tlen_pp_rev_dev_squared_sum += tlen_pp_rev_dev_squared             # <<<<<<<<<<<<<<
 *                 else:
 *                     tlen_pp_fwd_dev_squared = (tlen - tlen_pp_fwd_mean)**2
 */
          __pyx_v_tlen_pp_rev_dev_squared_sum = (__pyx_v_tlen_pp_rev_dev_squared_sum + __pyx_v_tlen_pp_rev_dev_squared);
          goto __pyx_L21;
        }
        /*else*/ {

          /* "pysamstats.pyx":1016
 *                     tlen_pp_rev_dev_squared_sum += tlen_pp_rev_dev_squared
 *                 else:
 *                     tlen_pp_fwd_dev_squared = (tlen - tlen_pp_fwd_mean)**2             # <<<<<<<<<<<<<<
 *                     tlen_pp_fwd_dev_squared_sum += tlen_pp_fwd_dev_squared
 * 
 */
          __pyx_v_tlen_pp_fwd_dev_squared = pow((__pyx_v_tlen - __pyx_v_tlen_pp_fwd_mean), 2.0);

          /* "pysamstats.pyx":1017
 *                 else:
 *                     tlen_pp_fwd_dev_squared = (tlen - tlen_pp_fwd_mean)**2
 *                     tlen_pp_fwd_dev_squared_sum += tlen_pp_fwd_dev_squared             # <<<<<<<<<<<<<<
 * 
 *     # calculate output variables
 */
          __pyx_v_tlen_pp_fwd_dev_squared_sum = (__pyx_v_tlen_pp_fwd_dev_squared_sum + __pyx_v_tlen_pp_fwd_dev_squared);
        }
        __pyx_L21:;
        goto __pyx_L20;
      }
      __pyx_L20:;
      goto __pyx_L18;
    }
    __pyx_L18:;
  }

  /* "pysamstats.pyx":1022
 *     # N.B. round values to nearest integer, any finer precision is probably not
 *     # interesting
 *     if reads_p > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen = int(round(tlen_p_mean))
 *         rms_tlen = int(round(sqrt(tlen_p_squared_sum * 1. / reads_p)))
 */
  __pyx_t_12 = (__pyx_v_reads_p > 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":1023
 *     # interesting
 *     if reads_p > 0:
 *         mean_tlen = int(round(tlen_p_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen = int(round(sqrt(tlen_p_squared_sum * 1. / reads_p)))
 *         variance_tlen = tlen_p_dev_squared_sum * 1. / reads_p
 */
    __pyx_t_4 = PyFloat_FromDouble(__pyx_v_tlen_p_mean); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1023; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_mean_tlen = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1024
 *     if reads_p > 0:
 *         mean_tlen = int(round(tlen_p_mean))
 *         rms_tlen = int(round(sqrt(tlen_p_squared_sum * 1. / reads_p)))             # <<<<<<<<<<<<<<
 *         variance_tlen = tlen_p_dev_squared_sum * 1. / reads_p
 *         std_tlen = int(round(sqrt(variance_tlen)))
 */
    __pyx_t_14 = (__pyx_v_tlen_p_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_p == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_14 / __pyx_v_reads_p))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_tlen = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1025
 *         mean_tlen = int(round(tlen_p_mean))
 *         rms_tlen = int(round(sqrt(tlen_p_squared_sum * 1. / reads_p)))
 *         variance_tlen = tlen_p_dev_squared_sum * 1. / reads_p             # <<<<<<<<<<<<<<
 *         std_tlen = int(round(sqrt(variance_tlen)))
 *     else:
 */
    __pyx_t_14 = (__pyx_v_tlen_p_dev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_p == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen = (__pyx_t_14 / __pyx_v_reads_p);

    /* "pysamstats.pyx":1026
 *         rms_tlen = int(round(sqrt(tlen_p_squared_sum * 1. / reads_p)))
 *         variance_tlen = tlen_p_dev_squared_sum * 1. / reads_p
 *         std_tlen = int(round(sqrt(variance_tlen)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = 'NA'
 */
    __pyx_t_4 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1026; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1026; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1026; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1026; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1026; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_std_tlen = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L22;
  }
  /*else*/ {

    /* "pysamstats.pyx":1028
 *         std_tlen = int(round(sqrt(variance_tlen)))
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = 'NA'             # <<<<<<<<<<<<<<
 *     if reads_p_rev > 0:
 *         mean_tlen_rev = int(round(tlen_p_rev_mean))
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_tlen = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_std_tlen = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_mean_tlen = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L22:;

  /* "pysamstats.pyx":1029
 *     else:
 *         rms_tlen = std_tlen = mean_tlen = 'NA'
 *     if reads_p_rev > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_rev = int(round(tlen_p_rev_mean))
 *         rms_tlen_rev = int(round(sqrt(tlen_p_rev_squared_sum * 1. / reads_p_rev)))
 */
  __pyx_t_12 = (__pyx_v_reads_p_rev > 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":1030
 *         rms_tlen = std_tlen = mean_tlen = 'NA'
 *     if reads_p_rev > 0:
 *         mean_tlen_rev = int(round(tlen_p_rev_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_rev = int(round(sqrt(tlen_p_rev_squared_sum * 1. / reads_p_rev)))
 *         variance_tlen_rev = tlen_p_rev_dev_squared_sum * 1. / reads_p_rev
 */
    __pyx_t_4 = PyFloat_FromDouble(__pyx_v_tlen_p_rev_mean); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1030; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1030; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_mean_tlen_rev = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1031
 *     if reads_p_rev > 0:
 *         mean_tlen_rev = int(round(tlen_p_rev_mean))
 *         rms_tlen_rev = int(round(sqrt(tlen_p_rev_squared_sum * 1. / reads_p_rev)))             # <<<<<<<<<<<<<<
 *         variance_tlen_rev = tlen_p_rev_dev_squared_sum * 1. / reads_p_rev
 *         std_tlen_rev = int(round(sqrt(variance_tlen_rev)))
 */
    __pyx_t_14 = (__pyx_v_tlen_p_rev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_p_rev == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_14 / __pyx_v_reads_p_rev))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_tlen_rev = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1032
 *         mean_tlen_rev = int(round(tlen_p_rev_mean))
 *         rms_tlen_rev = int(round(sqrt(tlen_p_rev_squared_sum * 1. / reads_p_rev)))
 *         variance_tlen_rev = tlen_p_rev_dev_squared_sum * 1. / reads_p_rev             # <<<<<<<<<<<<<<
 *         std_tlen_rev = int(round(sqrt(variance_tlen_rev)))
 *     else:
 */
    __pyx_t_14 = (__pyx_v_tlen_p_rev_dev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_p_rev == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_rev = (__pyx_t_14 / __pyx_v_reads_p_rev);

    /* "pysamstats.pyx":1033
 *         rms_tlen_rev = int(round(sqrt(tlen_p_rev_squared_sum * 1. / reads_p_rev)))
 *         variance_tlen_rev = tlen_p_rev_dev_squared_sum * 1. / reads_p_rev
 *         std_tlen_rev = int(round(sqrt(variance_tlen_rev)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen_rev = std_tlen_rev = mean_tlen_rev = 'NA'
 */
    __pyx_t_4 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_rev)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_std_tlen_rev = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L23;
  }
  /*else*/ {

    /* "pysamstats.pyx":1035
 *         std_tlen_rev = int(round(sqrt(variance_tlen_rev)))
 *     else:
 *         rms_tlen_rev = std_tlen_rev = mean_tlen_rev = 'NA'             # <<<<<<<<<<<<<<
 *     if reads_p_fwd > 0:
 *         mean_tlen_fwd = int(round(tlen_p_fwd_mean))
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_tlen_rev = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_std_tlen_rev = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_mean_tlen_rev = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L23:;

  /* "pysamstats.pyx":1036
 *     else:
 *         rms_tlen_rev = std_tlen_rev = mean_tlen_rev = 'NA'
 *     if reads_p_fwd > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_fwd = int(round(tlen_p_fwd_mean))
 *         rms_tlen_fwd = int(round(sqrt(tlen_p_fwd_squared_sum * 1. / reads_p_fwd)))
 */
  __pyx_t_12 = (__pyx_v_reads_p_fwd > 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":1037
 *         rms_tlen_rev = std_tlen_rev = mean_tlen_rev = 'NA'
 *     if reads_p_fwd > 0:
 *         mean_tlen_fwd = int(round(tlen_p_fwd_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_fwd = int(round(sqrt(tlen_p_fwd_squared_sum * 1. / reads_p_fwd)))
 *         variance_tlen_fwd = tlen_p_fwd_dev_squared_sum * 1. / reads_p_fwd
 */
    __pyx_t_4 = PyFloat_FromDouble(__pyx_v_tlen_p_fwd_mean); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_mean_tlen_fwd = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1038
 *     if reads_p_fwd > 0:
 *         mean_tlen_fwd = int(round(tlen_p_fwd_mean))
 *         rms_tlen_fwd = int(round(sqrt(tlen_p_fwd_squared_sum * 1. / reads_p_fwd)))             # <<<<<<<<<<<<<<
 *         variance_tlen_fwd = tlen_p_fwd_dev_squared_sum * 1. / reads_p_fwd
 *         std_tlen_fwd = int(round(sqrt(variance_tlen_fwd)))
 */
    __pyx_t_14 = (__pyx_v_tlen_p_fwd_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_p_fwd == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_14 / __pyx_v_reads_p_fwd))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_tlen_fwd = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1039
 *         mean_tlen_fwd = int(round(tlen_p_fwd_mean))
 *         rms_tlen_fwd = int(round(sqrt(tlen_p_fwd_squared_sum * 1. / reads_p_fwd)))
 *         variance_tlen_fwd = tlen_p_fwd_dev_squared_sum * 1. / reads_p_fwd             # <<<<<<<<<<<<<<
 *         std_tlen_fwd = int(round(sqrt(variance_tlen_fwd)))
 *     else:
 */
    __pyx_t_14 = (__pyx_v_tlen_p_fwd_dev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_p_fwd == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_fwd = (__pyx_t_14 / __pyx_v_reads_p_fwd);

    /* "pysamstats.pyx":1040
 *         rms_tlen_fwd = int(round(sqrt(tlen_p_fwd_squared_sum * 1. / reads_p_fwd)))
 *         variance_tlen_fwd = tlen_p_fwd_dev_squared_sum * 1. / reads_p_fwd
 *         std_tlen_fwd = int(round(sqrt(variance_tlen_fwd)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen_fwd = std_tlen_fwd = mean_tlen_fwd = 'NA'
 */
    __pyx_t_4 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_fwd)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_std_tlen_fwd = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L24;
  }
  /*else*/ {

    /* "pysamstats.pyx":1042
 *         std_tlen_fwd = int(round(sqrt(variance_tlen_fwd)))
 *     else:
 *         rms_tlen_fwd = std_tlen_fwd = mean_tlen_fwd = 'NA'             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_tlen_fwd = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_std_tlen_fwd = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_mean_tlen_fwd = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L24:;

  /* "pysamstats.pyx":1043
 *     else:
 *         rms_tlen_fwd = std_tlen_fwd = mean_tlen_fwd = 'NA'
 *     if reads_pp > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = int(round(sqrt(tlen_pp_squared_sum * 1. / reads_pp)))
 */
  __pyx_t_12 = (__pyx_v_reads_pp > 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":1044
 *         rms_tlen_fwd = std_tlen_fwd = mean_tlen_fwd = 'NA'
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_pp = int(round(sqrt(tlen_pp_squared_sum * 1. / reads_pp)))
 *         variance_tlen_pp = tlen_pp_dev_squared_sum * 1. / reads_pp
 */
    __pyx_t_4 = PyFloat_FromDouble(__pyx_v_tlen_pp_mean); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1044; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_mean_tlen_pp = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1045
 *     if reads_pp > 0:
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = int(round(sqrt(tlen_pp_squared_sum * 1. / reads_pp)))             # <<<<<<<<<<<<<<
 *         variance_tlen_pp = tlen_pp_dev_squared_sum * 1. / reads_pp
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 */
    __pyx_t_14 = (__pyx_v_tlen_pp_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_14 / __pyx_v_reads_pp))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1045; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1045; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1045; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_tlen_pp = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1046
 *         mean_tlen_pp = int(round(tlen_pp_mean))
 *         rms_tlen_pp = int(round(sqrt(tlen_pp_squared_sum * 1. / reads_pp)))
 *         variance_tlen_pp = tlen_pp_dev_squared_sum * 1. / reads_pp             # <<<<<<<<<<<<<<
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 *     else:
 */
    __pyx_t_14 = (__pyx_v_tlen_pp_dev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_pp = (__pyx_t_14 / __pyx_v_reads_pp);

    /* "pysamstats.pyx":1047
 *         rms_tlen_pp = int(round(sqrt(tlen_pp_squared_sum * 1. / reads_pp)))
 *         variance_tlen_pp = tlen_pp_dev_squared_sum * 1. / reads_pp
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 'NA'
 */
    __pyx_t_4 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_pp)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_std_tlen_pp = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L25;
  }
  /*else*/ {

    /* "pysamstats.pyx":1049
 *         std_tlen_pp = int(round(sqrt(variance_tlen_pp)))
 *     else:
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 'NA'             # <<<<<<<<<<<<<<
 *     if reads_pp_rev > 0:
 *         mean_tlen_pp_rev = int(round(tlen_pp_rev_mean))
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_tlen_pp = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_std_tlen_pp = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_mean_tlen_pp = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L25:;

  /* "pysamstats.pyx":1050
 *     else:
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 'NA'
 *     if reads_pp_rev > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_pp_rev = int(round(tlen_pp_rev_mean))
 *         rms_tlen_pp_rev = int(round(sqrt(tlen_pp_rev_squared_sum * 1. / reads_pp_rev)))
 */
  __pyx_t_12 = (__pyx_v_reads_pp_rev > 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":1051
 *         rms_tlen_pp = std_tlen_pp = mean_tlen_pp = 'NA'
 *     if reads_pp_rev > 0:
 *         mean_tlen_pp_rev = int(round(tlen_pp_rev_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_pp_rev = int(round(sqrt(tlen_pp_rev_squared_sum * 1. / reads_pp_rev)))
 *         variance_tlen_pp_rev = tlen_pp_rev_dev_squared_sum * 1. / reads_pp_rev
 */
    __pyx_t_4 = PyFloat_FromDouble(__pyx_v_tlen_pp_rev_mean); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_mean_tlen_pp_rev = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1052
 *     if reads_pp_rev > 0:
 *         mean_tlen_pp_rev = int(round(tlen_pp_rev_mean))
 *         rms_tlen_pp_rev = int(round(sqrt(tlen_pp_rev_squared_sum * 1. / reads_pp_rev)))             # <<<<<<<<<<<<<<
 *         variance_tlen_pp_rev = tlen_pp_rev_dev_squared_sum * 1. / reads_pp_rev
 *         std_tlen_pp_rev = int(round(sqrt(variance_tlen_pp_rev)))
 */
    __pyx_t_14 = (__pyx_v_tlen_pp_rev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp_rev == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_14 / __pyx_v_reads_pp_rev))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_tlen_pp_rev = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1053
 *         mean_tlen_pp_rev = int(round(tlen_pp_rev_mean))
 *         rms_tlen_pp_rev = int(round(sqrt(tlen_pp_rev_squared_sum * 1. / reads_pp_rev)))
 *         variance_tlen_pp_rev = tlen_pp_rev_dev_squared_sum * 1. / reads_pp_rev             # <<<<<<<<<<<<<<
 *         std_tlen_pp_rev = int(round(sqrt(variance_tlen_pp_rev)))
 *     else:
 */
    __pyx_t_14 = (__pyx_v_tlen_pp_rev_dev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp_rev == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_pp_rev = (__pyx_t_14 / __pyx_v_reads_pp_rev);

    /* "pysamstats.pyx":1054
 *         rms_tlen_pp_rev = int(round(sqrt(tlen_pp_rev_squared_sum * 1. / reads_pp_rev)))
 *         variance_tlen_pp_rev = tlen_pp_rev_dev_squared_sum * 1. / reads_pp_rev
 *         std_tlen_pp_rev = int(round(sqrt(variance_tlen_pp_rev)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen_pp_rev = std_tlen_pp_rev = mean_tlen_pp_rev = 'NA'
 */
    __pyx_t_4 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_pp_rev)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_std_tlen_pp_rev = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L26;
  }
  /*else*/ {

    /* "pysamstats.pyx":1056
 *         std_tlen_pp_rev = int(round(sqrt(variance_tlen_pp_rev)))
 *     else:
 *         rms_tlen_pp_rev = std_tlen_pp_rev = mean_tlen_pp_rev = 'NA'             # <<<<<<<<<<<<<<
 *     if reads_pp_fwd > 0:
 *         mean_tlen_pp_fwd = int(round(tlen_pp_fwd_mean))
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_tlen_pp_rev = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_std_tlen_pp_rev = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_mean_tlen_pp_rev = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L26:;

  /* "pysamstats.pyx":1057
 *     else:
 *         rms_tlen_pp_rev = std_tlen_pp_rev = mean_tlen_pp_rev = 'NA'
 *     if reads_pp_fwd > 0:             # <<<<<<<<<<<<<<
 *         mean_tlen_pp_fwd = int(round(tlen_pp_fwd_mean))
 *         rms_tlen_pp_fwd = int(round(sqrt(tlen_pp_fwd_squared_sum * 1. / reads_pp_fwd)))
 */
  __pyx_t_12 = (__pyx_v_reads_pp_fwd > 0);
  if (__pyx_t_12) {

    /* "pysamstats.pyx":1058
 *         rms_tlen_pp_rev = std_tlen_pp_rev = mean_tlen_pp_rev = 'NA'
 *     if reads_pp_fwd > 0:
 *         mean_tlen_pp_fwd = int(round(tlen_pp_fwd_mean))             # <<<<<<<<<<<<<<
 *         rms_tlen_pp_fwd = int(round(sqrt(tlen_pp_fwd_squared_sum * 1. / reads_pp_fwd)))
 *         variance_tlen_pp_fwd = tlen_pp_fwd_dev_squared_sum * 1. / reads_pp_fwd
 */
    __pyx_t_4 = PyFloat_FromDouble(__pyx_v_tlen_pp_fwd_mean); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(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 = 0;
    __pyx_t_4 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 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 = 0;
    __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_mean_tlen_pp_fwd = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1059
 *     if reads_pp_fwd > 0:
 *         mean_tlen_pp_fwd = int(round(tlen_pp_fwd_mean))
 *         rms_tlen_pp_fwd = int(round(sqrt(tlen_pp_fwd_squared_sum * 1. / reads_pp_fwd)))             # <<<<<<<<<<<<<<
 *         variance_tlen_pp_fwd = tlen_pp_fwd_dev_squared_sum * 1. / reads_pp_fwd
 *         std_tlen_pp_fwd = int(round(sqrt(variance_tlen_pp_fwd)))
 */
    __pyx_t_14 = (__pyx_v_tlen_pp_fwd_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp_fwd == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_14 / __pyx_v_reads_pp_fwd))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_tlen_pp_fwd = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1060
 *         mean_tlen_pp_fwd = int(round(tlen_pp_fwd_mean))
 *         rms_tlen_pp_fwd = int(round(sqrt(tlen_pp_fwd_squared_sum * 1. / reads_pp_fwd)))
 *         variance_tlen_pp_fwd = tlen_pp_fwd_dev_squared_sum * 1. / reads_pp_fwd             # <<<<<<<<<<<<<<
 *         std_tlen_pp_fwd = int(round(sqrt(variance_tlen_pp_fwd)))
 *     else:
 */
    __pyx_t_14 = (__pyx_v_tlen_pp_fwd_dev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp_fwd == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_variance_tlen_pp_fwd = (__pyx_t_14 / __pyx_v_reads_pp_fwd);

    /* "pysamstats.pyx":1061
 *         rms_tlen_pp_fwd = int(round(sqrt(tlen_pp_fwd_squared_sum * 1. / reads_pp_fwd)))
 *         variance_tlen_pp_fwd = tlen_pp_fwd_dev_squared_sum * 1. / reads_pp_fwd
 *         std_tlen_pp_fwd = int(round(sqrt(variance_tlen_pp_fwd)))             # <<<<<<<<<<<<<<
 *     else:
 *         rms_tlen_pp_fwd = std_tlen_pp_fwd = mean_tlen_pp_fwd = 'NA'
 */
    __pyx_t_4 = PyFloat_FromDouble(sqrt(__pyx_v_variance_tlen_pp_fwd)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_std_tlen_pp_fwd = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L27;
  }
  /*else*/ {

    /* "pysamstats.pyx":1063
 *         std_tlen_pp_fwd = int(round(sqrt(variance_tlen_pp_fwd)))
 *     else:
 *         rms_tlen_pp_fwd = std_tlen_pp_fwd = mean_tlen_pp_fwd = 'NA'             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom,
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_tlen_pp_fwd = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_std_tlen_pp_fwd = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_mean_tlen_pp_fwd = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L27:;

  /* "pysamstats.pyx":1065
 *         rms_tlen_pp_fwd = std_tlen_pp_fwd = mean_tlen_pp_fwd = 'NA'
 * 
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 * #            'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1066
 * 
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 * #            'reads_all': n,
 * #            'reads_fwd': reads_fwd,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1076
 * #            'reads_pp_fwd': reads_pp_fwd,
 * #            'reads_pp_rev': reads_pp_rev,
 *             'mean_tlen': mean_tlen,             # <<<<<<<<<<<<<<
 *             'mean_tlen_fwd': mean_tlen_fwd,
 *             'mean_tlen_rev': mean_tlen_rev,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__mean_tlen), __pyx_v_mean_tlen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1077
 * #            'reads_pp_rev': reads_pp_rev,
 *             'mean_tlen': mean_tlen,
 *             'mean_tlen_fwd': mean_tlen_fwd,             # <<<<<<<<<<<<<<
 *             'mean_tlen_rev': mean_tlen_rev,
 *             'mean_tlen_pp': mean_tlen_pp,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__mean_tlen_fwd), __pyx_v_mean_tlen_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1078
 *             'mean_tlen': mean_tlen,
 *             'mean_tlen_fwd': mean_tlen_fwd,
 *             'mean_tlen_rev': mean_tlen_rev,             # <<<<<<<<<<<<<<
 *             'mean_tlen_pp': mean_tlen_pp,
 *             'mean_tlen_pp_fwd': mean_tlen_pp_fwd,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__mean_tlen_rev), __pyx_v_mean_tlen_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1079
 *             'mean_tlen_fwd': mean_tlen_fwd,
 *             'mean_tlen_rev': mean_tlen_rev,
 *             'mean_tlen_pp': mean_tlen_pp,             # <<<<<<<<<<<<<<
 *             'mean_tlen_pp_fwd': mean_tlen_pp_fwd,
 *             'mean_tlen_pp_rev': mean_tlen_pp_rev,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__mean_tlen_pp), __pyx_v_mean_tlen_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1080
 *             'mean_tlen_rev': mean_tlen_rev,
 *             'mean_tlen_pp': mean_tlen_pp,
 *             'mean_tlen_pp_fwd': mean_tlen_pp_fwd,             # <<<<<<<<<<<<<<
 *             'mean_tlen_pp_rev': mean_tlen_pp_rev,
 *             'rms_tlen': rms_tlen,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__mean_tlen_pp_fwd), __pyx_v_mean_tlen_pp_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1081
 *             'mean_tlen_pp': mean_tlen_pp,
 *             'mean_tlen_pp_fwd': mean_tlen_pp_fwd,
 *             'mean_tlen_pp_rev': mean_tlen_pp_rev,             # <<<<<<<<<<<<<<
 *             'rms_tlen': rms_tlen,
 *             'rms_tlen_fwd': rms_tlen_fwd,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__mean_tlen_pp_rev), __pyx_v_mean_tlen_pp_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1082
 *             'mean_tlen_pp_fwd': mean_tlen_pp_fwd,
 *             'mean_tlen_pp_rev': mean_tlen_pp_rev,
 *             'rms_tlen': rms_tlen,             # <<<<<<<<<<<<<<
 *             'rms_tlen_fwd': rms_tlen_fwd,
 *             'rms_tlen_rev': rms_tlen_rev,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_tlen), __pyx_v_rms_tlen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1083
 *             'mean_tlen_pp_rev': mean_tlen_pp_rev,
 *             'rms_tlen': rms_tlen,
 *             'rms_tlen_fwd': rms_tlen_fwd,             # <<<<<<<<<<<<<<
 *             'rms_tlen_rev': rms_tlen_rev,
 *             'rms_tlen_pp': rms_tlen_pp,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_tlen_fwd), __pyx_v_rms_tlen_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1084
 *             'rms_tlen': rms_tlen,
 *             'rms_tlen_fwd': rms_tlen_fwd,
 *             'rms_tlen_rev': rms_tlen_rev,             # <<<<<<<<<<<<<<
 *             'rms_tlen_pp': rms_tlen_pp,
 *             'rms_tlen_pp_fwd': rms_tlen_pp_fwd,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_tlen_rev), __pyx_v_rms_tlen_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1085
 *             'rms_tlen_fwd': rms_tlen_fwd,
 *             'rms_tlen_rev': rms_tlen_rev,
 *             'rms_tlen_pp': rms_tlen_pp,             # <<<<<<<<<<<<<<
 *             'rms_tlen_pp_fwd': rms_tlen_pp_fwd,
 *             'rms_tlen_pp_rev': rms_tlen_pp_rev,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_tlen_pp), __pyx_v_rms_tlen_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1086
 *             'rms_tlen_rev': rms_tlen_rev,
 *             'rms_tlen_pp': rms_tlen_pp,
 *             'rms_tlen_pp_fwd': rms_tlen_pp_fwd,             # <<<<<<<<<<<<<<
 *             'rms_tlen_pp_rev': rms_tlen_pp_rev,
 *             'std_tlen': std_tlen,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_tlen_pp_fwd), __pyx_v_rms_tlen_pp_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1087
 *             'rms_tlen_pp': rms_tlen_pp,
 *             'rms_tlen_pp_fwd': rms_tlen_pp_fwd,
 *             'rms_tlen_pp_rev': rms_tlen_pp_rev,             # <<<<<<<<<<<<<<
 *             'std_tlen': std_tlen,
 *             'std_tlen_fwd': std_tlen_fwd,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_tlen_pp_rev), __pyx_v_rms_tlen_pp_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1088
 *             'rms_tlen_pp_fwd': rms_tlen_pp_fwd,
 *             'rms_tlen_pp_rev': rms_tlen_pp_rev,
 *             'std_tlen': std_tlen,             # <<<<<<<<<<<<<<
 *             'std_tlen_fwd': std_tlen_fwd,
 *             'std_tlen_rev': std_tlen_rev,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__std_tlen), __pyx_v_std_tlen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1089
 *             'rms_tlen_pp_rev': rms_tlen_pp_rev,
 *             'std_tlen': std_tlen,
 *             'std_tlen_fwd': std_tlen_fwd,             # <<<<<<<<<<<<<<
 *             'std_tlen_rev': std_tlen_rev,
 *             'std_tlen_pp': std_tlen_pp,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__std_tlen_fwd), __pyx_v_std_tlen_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1090
 *             'std_tlen': std_tlen,
 *             'std_tlen_fwd': std_tlen_fwd,
 *             'std_tlen_rev': std_tlen_rev,             # <<<<<<<<<<<<<<
 *             'std_tlen_pp': std_tlen_pp,
 *             'std_tlen_pp_fwd': std_tlen_pp_fwd,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__std_tlen_rev), __pyx_v_std_tlen_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1091
 *             'std_tlen_fwd': std_tlen_fwd,
 *             'std_tlen_rev': std_tlen_rev,
 *             'std_tlen_pp': std_tlen_pp,             # <<<<<<<<<<<<<<
 *             'std_tlen_pp_fwd': std_tlen_pp_fwd,
 *             'std_tlen_pp_rev': std_tlen_pp_rev}
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__std_tlen_pp), __pyx_v_std_tlen_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1092
 *             'std_tlen_rev': std_tlen_rev,
 *             'std_tlen_pp': std_tlen_pp,
 *             'std_tlen_pp_fwd': std_tlen_pp_fwd,             # <<<<<<<<<<<<<<
 *             'std_tlen_pp_rev': std_tlen_pp_rev}
 * 
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__std_tlen_pp_fwd), __pyx_v_std_tlen_pp_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1093
 *             'std_tlen_pp': std_tlen_pp,
 *             'std_tlen_pp_fwd': std_tlen_pp_fwd,
 *             'std_tlen_pp_rev': std_tlen_pp_rev}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__std_tlen_pp_rev), __pyx_v_std_tlen_pp_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1065; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_tlen_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_mean_tlen);
  __Pyx_XDECREF(__pyx_v_rms_tlen);
  __Pyx_XDECREF(__pyx_v_std_tlen);
  __Pyx_XDECREF(__pyx_v_mean_tlen_rev);
  __Pyx_XDECREF(__pyx_v_rms_tlen_rev);
  __Pyx_XDECREF(__pyx_v_std_tlen_rev);
  __Pyx_XDECREF(__pyx_v_mean_tlen_fwd);
  __Pyx_XDECREF(__pyx_v_rms_tlen_fwd);
  __Pyx_XDECREF(__pyx_v_std_tlen_fwd);
  __Pyx_XDECREF(__pyx_v_mean_tlen_pp);
  __Pyx_XDECREF(__pyx_v_rms_tlen_pp);
  __Pyx_XDECREF(__pyx_v_std_tlen_pp);
  __Pyx_XDECREF(__pyx_v_mean_tlen_pp_rev);
  __Pyx_XDECREF(__pyx_v_rms_tlen_pp_rev);
  __Pyx_XDECREF(__pyx_v_std_tlen_pp_rev);
  __Pyx_XDECREF(__pyx_v_mean_tlen_pp_fwd);
  __Pyx_XDECREF(__pyx_v_rms_tlen_pp_fwd);
  __Pyx_XDECREF(__pyx_v_std_tlen_pp_fwd);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_50construct_rec_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_50construct_rec_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_tlen_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__col,&__pyx_n_s__one_based,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__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_tlen_strand", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_tlen_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[1]);
    if (values[2]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":860
 * 
 * cpdef object construct_rec_tlen_strand(Samfile samfile, PileupProxy col,
 *                                        bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_tlen_strand", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_tlen_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_49construct_rec_tlen_strand(__pyx_self, __pyx_v_samfile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":859
 * 
 * 
 * cpdef object construct_rec_tlen_strand(Samfile samfile, PileupProxy col,             # <<<<<<<<<<<<<<
 *                                        bint one_based=False):
 * 
 */

static PyObject *__pyx_pf_10pysamstats_49construct_rec_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_tlen_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_tlen_strand", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_tlen_strand(__pyx_v_samfile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_tlen_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_53generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_52stat_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_52stat_tlen_strand = {__Pyx_NAMESTR("stat_tlen_strand"), (PyCFunction)__pyx_pw_10pysamstats_52stat_tlen_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_52stat_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_tlen_strand (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__samfile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysamstats.pyx":1096
 * 
 * 
 * def stat_tlen_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_28;
    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__chrom);
          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__one_based);
          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, "stat_tlen_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
    __pyx_v_one_based = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_tlen_strand", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_tlen_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_51stat_tlen_strand(__pyx_self, __pyx_v_samfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_51stat_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_tlen_strand", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *)__pyx_ptype_10pysamstats___pyx_scope_struct_7_stat_tlen_strand->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_7_stat_tlen_strand, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_53generator7, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_tlen_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_53generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_tlen_strand __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1097
 * 
 * def stat_tlen_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_tlen_strand(samfile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1098
 * def stat_tlen_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_tlen_strand(samfile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1098; __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 = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1098; __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 = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1098; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":1099
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_tlen_strand(samfile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_tlen_strand(__pyx_cur_scope->__pyx_v_samfile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_tlen_strand", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_55write_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_55write_tlen_strand = {__Pyx_NAMESTR("write_tlen_strand"), (PyCFunction)__pyx_pw_10pysamstats_55write_tlen_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_55write_tlen_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_tlen_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_tlen_strand", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_54write_tlen_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1102
 * 
 * 
 * def write_tlen_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 */

static PyObject *__pyx_pf_10pysamstats_54write_tlen_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_tlen_strand", 0);

  /* "pysamstats.pyx":1103
 * 
 * def write_tlen_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 * #                  'reads_paired', 'reads_paired_fwd', 'reads_paired_rev',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_29));
  __pyx_v_fieldnames = __pyx_k_tuple_29;

  /* "pysamstats.pyx":1113
 *                   'std_tlen', 'std_tlen_fwd', 'std_tlen_rev',
 *                   'std_tlen_pp', 'std_tlen_pp_fwd', 'std_tlen_pp_rev')
 *     write_stats(stat_tlen_strand, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_tlen_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __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 = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1113; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_tlen_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1121
 * 
 * 
 * cpdef object construct_rec_mapq(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */

static PyObject *__pyx_pw_10pysamstats_57construct_rec_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_mapq(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_mapq *__pyx_optional_args) {
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  uint64_t __pyx_v_mapq;
  uint64_t __pyx_v_mapq_max;
  uint64_t __pyx_v_mapq_pp_max;
  uint64_t __pyx_v_mapq_squared;
  uint64_t __pyx_v_mapq_squared_sum;
  uint64_t __pyx_v_mapq_pp_squared_sum;
  int __pyx_v_is_proper_pair;
  unsigned int __pyx_v_reads_pp;
  unsigned int __pyx_v_reads_mapq0;
  unsigned int __pyx_v_reads_mapq0_pp;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_v_rms_mapq = NULL;
  uint64_t __pyx_v_max_mapq;
  PyObject *__pyx_v_rms_mapq_pp = NULL;
  PyObject *__pyx_v_max_mapq_pp = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int __pyx_t_10;
  double __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_mapq", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":1131
 *     cdef uint32_t flag
 *     cdef uint64_t mapq
 *     cdef uint64_t mapq_max = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_pp_max = 0
 *     cdef uint64_t mapq_squared
 */
  __pyx_v_mapq_max = 0;

  /* "pysamstats.pyx":1132
 *     cdef uint64_t mapq
 *     cdef uint64_t mapq_max = 0
 *     cdef uint64_t mapq_pp_max = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_squared
 *     cdef uint64_t mapq_squared_sum = 0
 */
  __pyx_v_mapq_pp_max = 0;

  /* "pysamstats.pyx":1134
 *     cdef uint64_t mapq_pp_max = 0
 *     cdef uint64_t mapq_squared
 *     cdef uint64_t mapq_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_pp_squared_sum = 0
 *     cdef bint is_proper_pair
 */
  __pyx_v_mapq_squared_sum = 0;

  /* "pysamstats.pyx":1135
 *     cdef uint64_t mapq_squared
 *     cdef uint64_t mapq_squared_sum = 0
 *     cdef uint64_t mapq_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef bint is_proper_pair
 *     cdef unsigned int reads_pp = 0
 */
  __pyx_v_mapq_pp_squared_sum = 0;

  /* "pysamstats.pyx":1137
 *     cdef uint64_t mapq_pp_squared_sum = 0
 *     cdef bint is_proper_pair
 *     cdef unsigned int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mapq0 = 0
 *     cdef unsigned int reads_mapq0_pp = 0
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":1138
 *     cdef bint is_proper_pair
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_mapq0 = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mapq0_pp = 0
 * 
 */
  __pyx_v_reads_mapq0 = 0;

  /* "pysamstats.pyx":1139
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_mapq0 = 0
 *     cdef unsigned int reads_mapq0_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_reads_mapq0_pp = 0;

  /* "pysamstats.pyx":1142
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); 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_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__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_v_n = __pyx_t_2;

  /* "pysamstats.pyx":1143
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":1146
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1146; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1147
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":1150
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":1151
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":1152
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":1153
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         mapq = aln.core.qual
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":1154
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         mapq = aln.core.qual
 *         mapq_squared = mapq**2
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":1155
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         mapq = aln.core.qual             # <<<<<<<<<<<<<<
 *         mapq_squared = mapq**2
 *         mapq_squared_sum += mapq_squared
 */
    __pyx_t_9 = __pyx_v_aln->core.qual;
    __pyx_v_mapq = __pyx_t_9;

    /* "pysamstats.pyx":1156
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         mapq = aln.core.qual
 *         mapq_squared = mapq**2             # <<<<<<<<<<<<<<
 *         mapq_squared_sum += mapq_squared
 *         if mapq == 0:
 */
    __pyx_v_mapq_squared = __Pyx_pow_uint64_t(__pyx_v_mapq, 2);

    /* "pysamstats.pyx":1157
 *         mapq = aln.core.qual
 *         mapq_squared = mapq**2
 *         mapq_squared_sum += mapq_squared             # <<<<<<<<<<<<<<
 *         if mapq == 0:
 *             reads_mapq0 += 1
 */
    __pyx_v_mapq_squared_sum = (__pyx_v_mapq_squared_sum + __pyx_v_mapq_squared);

    /* "pysamstats.pyx":1158
 *         mapq_squared = mapq**2
 *         mapq_squared_sum += mapq_squared
 *         if mapq == 0:             # <<<<<<<<<<<<<<
 *             reads_mapq0 += 1
 *         if mapq > mapq_max:
 */
    __pyx_t_10 = (__pyx_v_mapq == 0);
    if (__pyx_t_10) {

      /* "pysamstats.pyx":1159
 *         mapq_squared_sum += mapq_squared
 *         if mapq == 0:
 *             reads_mapq0 += 1             # <<<<<<<<<<<<<<
 *         if mapq > mapq_max:
 *             mapq_max = mapq
 */
      __pyx_v_reads_mapq0 = (__pyx_v_reads_mapq0 + 1);
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "pysamstats.pyx":1160
 *         if mapq == 0:
 *             reads_mapq0 += 1
 *         if mapq > mapq_max:             # <<<<<<<<<<<<<<
 *             mapq_max = mapq
 *         if is_proper_pair:
 */
    __pyx_t_10 = (__pyx_v_mapq > __pyx_v_mapq_max);
    if (__pyx_t_10) {

      /* "pysamstats.pyx":1161
 *             reads_mapq0 += 1
 *         if mapq > mapq_max:
 *             mapq_max = mapq             # <<<<<<<<<<<<<<
 *         if is_proper_pair:
 *             reads_pp += 1
 */
      __pyx_v_mapq_max = __pyx_v_mapq;
      goto __pyx_L6;
    }
    __pyx_L6:;

    /* "pysamstats.pyx":1162
 *         if mapq > mapq_max:
 *             mapq_max = mapq
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *             mapq_pp_squared_sum += mapq_squared
 */
    if (__pyx_v_is_proper_pair) {

      /* "pysamstats.pyx":1163
 *             mapq_max = mapq
 *         if is_proper_pair:
 *             reads_pp += 1             # <<<<<<<<<<<<<<
 *             mapq_pp_squared_sum += mapq_squared
 *             if mapq > mapq_pp_max:
 */
      __pyx_v_reads_pp = (__pyx_v_reads_pp + 1);

      /* "pysamstats.pyx":1164
 *         if is_proper_pair:
 *             reads_pp += 1
 *             mapq_pp_squared_sum += mapq_squared             # <<<<<<<<<<<<<<
 *             if mapq > mapq_pp_max:
 *                 mapq_pp_max = mapq
 */
      __pyx_v_mapq_pp_squared_sum = (__pyx_v_mapq_pp_squared_sum + __pyx_v_mapq_squared);

      /* "pysamstats.pyx":1165
 *             reads_pp += 1
 *             mapq_pp_squared_sum += mapq_squared
 *             if mapq > mapq_pp_max:             # <<<<<<<<<<<<<<
 *                 mapq_pp_max = mapq
 *             if mapq == 0:
 */
      __pyx_t_10 = (__pyx_v_mapq > __pyx_v_mapq_pp_max);
      if (__pyx_t_10) {

        /* "pysamstats.pyx":1166
 *             mapq_pp_squared_sum += mapq_squared
 *             if mapq > mapq_pp_max:
 *                 mapq_pp_max = mapq             # <<<<<<<<<<<<<<
 *             if mapq == 0:
 *                 reads_mapq0_pp += 1
 */
        __pyx_v_mapq_pp_max = __pyx_v_mapq;
        goto __pyx_L8;
      }
      __pyx_L8:;

      /* "pysamstats.pyx":1167
 *             if mapq > mapq_pp_max:
 *                 mapq_pp_max = mapq
 *             if mapq == 0:             # <<<<<<<<<<<<<<
 *                 reads_mapq0_pp += 1
 * 
 */
      __pyx_t_10 = (__pyx_v_mapq == 0);
      if (__pyx_t_10) {

        /* "pysamstats.pyx":1168
 *                 mapq_pp_max = mapq
 *             if mapq == 0:
 *                 reads_mapq0_pp += 1             # <<<<<<<<<<<<<<
 * 
 *     # construct output variables
 */
        __pyx_v_reads_mapq0_pp = (__pyx_v_reads_mapq0_pp + 1);
        goto __pyx_L9;
      }
      __pyx_L9:;
      goto __pyx_L7;
    }
    __pyx_L7:;
  }

  /* "pysamstats.pyx":1171
 * 
 *     # construct output variables
 *     rms_mapq = int(round(sqrt(mapq_squared_sum * 1. / n)))             # <<<<<<<<<<<<<<
 *     max_mapq = mapq_max
 *     if reads_pp > 0:
 */
  __pyx_t_11 = (__pyx_v_mapq_squared_sum * 1.);
  if (unlikely(__pyx_v_n == 0)) {
    PyErr_Format(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_11 / __pyx_v_n))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1171; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_rms_mapq = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1172
 *     # construct output variables
 *     rms_mapq = int(round(sqrt(mapq_squared_sum * 1. / n)))
 *     max_mapq = mapq_max             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         rms_mapq_pp = int(round(sqrt(mapq_pp_squared_sum * 1. / reads_pp)))
 */
  __pyx_v_max_mapq = __pyx_v_mapq_max;

  /* "pysamstats.pyx":1173
 *     rms_mapq = int(round(sqrt(mapq_squared_sum * 1. / n)))
 *     max_mapq = mapq_max
 *     if reads_pp > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_pp = int(round(sqrt(mapq_pp_squared_sum * 1. / reads_pp)))
 *         max_mapq_pp = mapq_pp_max
 */
  __pyx_t_10 = (__pyx_v_reads_pp > 0);
  if (__pyx_t_10) {

    /* "pysamstats.pyx":1174
 *     max_mapq = mapq_max
 *     if reads_pp > 0:
 *         rms_mapq_pp = int(round(sqrt(mapq_pp_squared_sum * 1. / reads_pp)))             # <<<<<<<<<<<<<<
 *         max_mapq_pp = mapq_pp_max
 *     else:
 */
    __pyx_t_11 = (__pyx_v_mapq_pp_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_11 / __pyx_v_reads_pp))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_mapq_pp = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1175
 *     if reads_pp > 0:
 *         rms_mapq_pp = int(round(sqrt(mapq_pp_squared_sum * 1. / reads_pp)))
 *         max_mapq_pp = mapq_pp_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_pp = max_mapq_pp = 'NA'
 */
    __pyx_t_4 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_mapq_pp_max); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_max_mapq_pp = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L10;
  }
  /*else*/ {

    /* "pysamstats.pyx":1177
 *         max_mapq_pp = mapq_pp_max
 *     else:
 *         rms_mapq_pp = max_mapq_pp = 'NA'             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom,
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_mapq_pp = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_max_mapq_pp = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L10:;

  /* "pysamstats.pyx":1179
 *         rms_mapq_pp = max_mapq_pp = 'NA'
 * 
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1180
 * 
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_pp': reads_pp,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1180; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1181
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp,
 *             'reads_mapq0': reads_mapq0,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_all), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1182
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *             'reads_mapq0': reads_mapq0,
 *             'reads_mapq0_pp': reads_mapq0_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1182; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1183
 *             'reads_all': n,
 *             'reads_pp': reads_pp,
 *             'reads_mapq0': reads_mapq0,             # <<<<<<<<<<<<<<
 *             'reads_mapq0_pp': reads_mapq0_pp,
 *             'rms_mapq': rms_mapq,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mapq0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1183; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_mapq0), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1184
 *             'reads_pp': reads_pp,
 *             'reads_mapq0': reads_mapq0,
 *             'reads_mapq0_pp': reads_mapq0_pp,             # <<<<<<<<<<<<<<
 *             'rms_mapq': rms_mapq,
 *             'rms_mapq_pp': rms_mapq_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mapq0_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1184; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_mapq0_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1185
 *             'reads_mapq0': reads_mapq0,
 *             'reads_mapq0_pp': reads_mapq0_pp,
 *             'rms_mapq': rms_mapq,             # <<<<<<<<<<<<<<
 *             'rms_mapq_pp': rms_mapq_pp,
 *             'max_mapq': max_mapq,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_mapq), __pyx_v_rms_mapq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1186
 *             'reads_mapq0_pp': reads_mapq0_pp,
 *             'rms_mapq': rms_mapq,
 *             'rms_mapq_pp': rms_mapq_pp,             # <<<<<<<<<<<<<<
 *             'max_mapq': max_mapq,
 *             'max_mapq_pp': max_mapq_pp}
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_mapq_pp), __pyx_v_rms_mapq_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1187
 *             'rms_mapq': rms_mapq,
 *             'rms_mapq_pp': rms_mapq_pp,
 *             'max_mapq': max_mapq,             # <<<<<<<<<<<<<<
 *             'max_mapq_pp': max_mapq_pp}
 * 
 */
  __pyx_t_5 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_max_mapq); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__max_mapq), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1188
 *             'rms_mapq_pp': rms_mapq_pp,
 *             'max_mapq': max_mapq,
 *             'max_mapq_pp': max_mapq_pp}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__max_mapq_pp), __pyx_v_max_mapq_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1179; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_rms_mapq);
  __Pyx_XDECREF(__pyx_v_rms_mapq_pp);
  __Pyx_XDECREF(__pyx_v_max_mapq_pp);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_57construct_rec_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_57construct_rec_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_mapq (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__col,&__pyx_n_s__one_based,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__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_mapq", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_mapq") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[1]);
    if (values[2]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1121
 * 
 * 
 * cpdef object construct_rec_mapq(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_mapq", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_56construct_rec_mapq(__pyx_self, __pyx_v_samfile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_56construct_rec_mapq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_mapq __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_mapq", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_mapq(__pyx_v_samfile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_60generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_59stat_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_59stat_mapq = {__Pyx_NAMESTR("stat_mapq"), (PyCFunction)__pyx_pw_10pysamstats_59stat_mapq, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_59stat_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_mapq (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__samfile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysamstats.pyx":1191
 * 
 * 
 * def stat_mapq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_30;
    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__chrom);
          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__one_based);
          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, "stat_mapq") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1191; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
    __pyx_v_one_based = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_mapq", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1191; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_58stat_mapq(__pyx_self, __pyx_v_samfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_58stat_mapq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_mapq", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *)__pyx_ptype_10pysamstats___pyx_scope_struct_8_stat_mapq->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_8_stat_mapq, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_60generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_60generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_mapq __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 1191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1192
 * 
 * def stat_mapq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_mapq(samfile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1192; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1193
 * def stat_mapq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_mapq(samfile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1193; __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 = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1193; __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 = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1193; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":1194
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_mapq(samfile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_mapq(__pyx_cur_scope->__pyx_v_samfile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_mapq", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_62write_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_62write_mapq = {__Pyx_NAMESTR("write_mapq"), (PyCFunction)__pyx_pw_10pysamstats_62write_mapq, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_62write_mapq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_mapq (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_mapq", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_61write_mapq(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1197
 * 
 * 
 * def write_mapq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all', 'reads_pp',
 */

static PyObject *__pyx_pf_10pysamstats_61write_mapq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_mapq", 0);

  /* "pysamstats.pyx":1198
 * 
 * def write_mapq(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *                   'reads_all', 'reads_pp',
 *                   'reads_mapq0', 'reads_mapq0_pp',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_31));
  __pyx_v_fieldnames = __pyx_k_tuple_31;

  /* "pysamstats.pyx":1203
 *                   'rms_mapq', 'rms_mapq_pp',
 *                   'max_mapq', 'max_mapq_pp')
 *     write_stats(stat_mapq, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_mapq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1203; __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 = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1203; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_mapq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1211
 * 
 * 
 * cpdef object construct_rec_mapq_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */

static PyObject *__pyx_pw_10pysamstats_64construct_rec_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_mapq_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_mapq_strand *__pyx_optional_args) {
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  uint64_t __pyx_v_mapq;
  uint64_t __pyx_v_mapq_squared;
  int __pyx_v_is_proper_pair;
  int __pyx_v_is_reverse;
  uint64_t __pyx_v_mapq_max;
  uint64_t __pyx_v_mapq_rev_max;
  uint64_t __pyx_v_mapq_fwd_max;
  uint64_t __pyx_v_mapq_pp_max;
  uint64_t __pyx_v_mapq_pp_rev_max;
  uint64_t __pyx_v_mapq_pp_fwd_max;
  uint64_t __pyx_v_mapq_squared_sum;
  uint64_t __pyx_v_mapq_fwd_squared_sum;
  uint64_t __pyx_v_mapq_rev_squared_sum;
  uint64_t __pyx_v_mapq_pp_squared_sum;
  uint64_t __pyx_v_mapq_pp_fwd_squared_sum;
  uint64_t __pyx_v_mapq_pp_rev_squared_sum;
  unsigned int __pyx_v_reads_rev;
  unsigned int __pyx_v_reads_fwd;
  unsigned int __pyx_v_reads_pp;
  unsigned int __pyx_v_reads_pp_rev;
  unsigned int __pyx_v_reads_pp_fwd;
  unsigned int __pyx_v_reads_mapq0;
  unsigned int __pyx_v_reads_mapq0_fwd;
  unsigned int __pyx_v_reads_mapq0_rev;
  unsigned int __pyx_v_reads_mapq0_pp;
  unsigned int __pyx_v_reads_mapq0_pp_fwd;
  unsigned int __pyx_v_reads_mapq0_pp_rev;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_v_rms_mapq = NULL;
  uint64_t __pyx_v_max_mapq;
  PyObject *__pyx_v_rms_mapq_rev = NULL;
  PyObject *__pyx_v_max_mapq_rev = NULL;
  PyObject *__pyx_v_rms_mapq_fwd = NULL;
  PyObject *__pyx_v_max_mapq_fwd = NULL;
  PyObject *__pyx_v_rms_mapq_pp = NULL;
  PyObject *__pyx_v_max_mapq_pp = NULL;
  PyObject *__pyx_v_rms_mapq_pp_fwd = NULL;
  PyObject *__pyx_v_max_mapq_pp_fwd = NULL;
  PyObject *__pyx_v_rms_mapq_pp_rev = NULL;
  PyObject *__pyx_v_max_mapq_pp_rev = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int __pyx_t_10;
  double __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_mapq_strand", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":1226
 *     cdef bint is_reverse
 * 
 *     cdef uint64_t mapq_max = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_rev_max = 0
 *     cdef uint64_t mapq_fwd_max = 0
 */
  __pyx_v_mapq_max = 0;

  /* "pysamstats.pyx":1227
 * 
 *     cdef uint64_t mapq_max = 0
 *     cdef uint64_t mapq_rev_max = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_fwd_max = 0
 *     cdef uint64_t mapq_pp_max = 0
 */
  __pyx_v_mapq_rev_max = 0;

  /* "pysamstats.pyx":1228
 *     cdef uint64_t mapq_max = 0
 *     cdef uint64_t mapq_rev_max = 0
 *     cdef uint64_t mapq_fwd_max = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_pp_max = 0
 *     cdef uint64_t mapq_pp_rev_max = 0
 */
  __pyx_v_mapq_fwd_max = 0;

  /* "pysamstats.pyx":1229
 *     cdef uint64_t mapq_rev_max = 0
 *     cdef uint64_t mapq_fwd_max = 0
 *     cdef uint64_t mapq_pp_max = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_pp_rev_max = 0
 *     cdef uint64_t mapq_pp_fwd_max = 0
 */
  __pyx_v_mapq_pp_max = 0;

  /* "pysamstats.pyx":1230
 *     cdef uint64_t mapq_fwd_max = 0
 *     cdef uint64_t mapq_pp_max = 0
 *     cdef uint64_t mapq_pp_rev_max = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_pp_fwd_max = 0
 *     cdef uint64_t mapq_squared_sum = 0
 */
  __pyx_v_mapq_pp_rev_max = 0;

  /* "pysamstats.pyx":1231
 *     cdef uint64_t mapq_pp_max = 0
 *     cdef uint64_t mapq_pp_rev_max = 0
 *     cdef uint64_t mapq_pp_fwd_max = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_squared_sum = 0
 *     cdef uint64_t mapq_fwd_squared_sum = 0
 */
  __pyx_v_mapq_pp_fwd_max = 0;

  /* "pysamstats.pyx":1232
 *     cdef uint64_t mapq_pp_rev_max = 0
 *     cdef uint64_t mapq_pp_fwd_max = 0
 *     cdef uint64_t mapq_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_fwd_squared_sum = 0
 *     cdef uint64_t mapq_rev_squared_sum = 0
 */
  __pyx_v_mapq_squared_sum = 0;

  /* "pysamstats.pyx":1233
 *     cdef uint64_t mapq_pp_fwd_max = 0
 *     cdef uint64_t mapq_squared_sum = 0
 *     cdef uint64_t mapq_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_rev_squared_sum = 0
 *     cdef uint64_t mapq_pp_squared_sum = 0
 */
  __pyx_v_mapq_fwd_squared_sum = 0;

  /* "pysamstats.pyx":1234
 *     cdef uint64_t mapq_squared_sum = 0
 *     cdef uint64_t mapq_fwd_squared_sum = 0
 *     cdef uint64_t mapq_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_pp_squared_sum = 0
 *     cdef uint64_t mapq_pp_fwd_squared_sum = 0
 */
  __pyx_v_mapq_rev_squared_sum = 0;

  /* "pysamstats.pyx":1235
 *     cdef uint64_t mapq_fwd_squared_sum = 0
 *     cdef uint64_t mapq_rev_squared_sum = 0
 *     cdef uint64_t mapq_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_pp_fwd_squared_sum = 0
 *     cdef uint64_t mapq_pp_rev_squared_sum = 0
 */
  __pyx_v_mapq_pp_squared_sum = 0;

  /* "pysamstats.pyx":1236
 *     cdef uint64_t mapq_rev_squared_sum = 0
 *     cdef uint64_t mapq_pp_squared_sum = 0
 *     cdef uint64_t mapq_pp_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t mapq_pp_rev_squared_sum = 0
 * 
 */
  __pyx_v_mapq_pp_fwd_squared_sum = 0;

  /* "pysamstats.pyx":1237
 *     cdef uint64_t mapq_pp_squared_sum = 0
 *     cdef uint64_t mapq_pp_fwd_squared_sum = 0
 *     cdef uint64_t mapq_pp_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef unsigned int reads_rev = 0
 */
  __pyx_v_mapq_pp_rev_squared_sum = 0;

  /* "pysamstats.pyx":1239
 *     cdef uint64_t mapq_pp_rev_squared_sum = 0
 * 
 *     cdef unsigned int reads_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_fwd = 0
 *     cdef unsigned int reads_pp = 0
 */
  __pyx_v_reads_rev = 0;

  /* "pysamstats.pyx":1240
 * 
 *     cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_rev = 0
 */
  __pyx_v_reads_fwd = 0;

  /* "pysamstats.pyx":1241
 *     cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_fwd = 0
 *     cdef unsigned int reads_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_rev = 0
 *     cdef unsigned int reads_pp_fwd = 0
 */
  __pyx_v_reads_pp = 0;

  /* "pysamstats.pyx":1242
 *     cdef unsigned int reads_fwd = 0
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_mapq0 = 0
 */
  __pyx_v_reads_pp_rev = 0;

  /* "pysamstats.pyx":1243
 *     cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_rev = 0
 *     cdef unsigned int reads_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mapq0 = 0
 *     cdef unsigned int reads_mapq0_fwd = 0
 */
  __pyx_v_reads_pp_fwd = 0;

  /* "pysamstats.pyx":1244
 *     cdef unsigned int reads_pp_rev = 0
 *     cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_mapq0 = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mapq0_fwd = 0
 *     cdef unsigned int reads_mapq0_rev = 0
 */
  __pyx_v_reads_mapq0 = 0;

  /* "pysamstats.pyx":1245
 *     cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_mapq0 = 0
 *     cdef unsigned int reads_mapq0_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mapq0_rev = 0
 *     cdef unsigned int reads_mapq0_pp = 0
 */
  __pyx_v_reads_mapq0_fwd = 0;

  /* "pysamstats.pyx":1246
 *     cdef unsigned int reads_mapq0 = 0
 *     cdef unsigned int reads_mapq0_fwd = 0
 *     cdef unsigned int reads_mapq0_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mapq0_pp = 0
 *     cdef unsigned int reads_mapq0_pp_fwd = 0
 */
  __pyx_v_reads_mapq0_rev = 0;

  /* "pysamstats.pyx":1247
 *     cdef unsigned int reads_mapq0_fwd = 0
 *     cdef unsigned int reads_mapq0_rev = 0
 *     cdef unsigned int reads_mapq0_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mapq0_pp_fwd = 0
 *     cdef unsigned int reads_mapq0_pp_rev = 0
 */
  __pyx_v_reads_mapq0_pp = 0;

  /* "pysamstats.pyx":1248
 *     cdef unsigned int reads_mapq0_rev = 0
 *     cdef unsigned int reads_mapq0_pp = 0
 *     cdef unsigned int reads_mapq0_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_mapq0_pp_rev = 0
 * 
 */
  __pyx_v_reads_mapq0_pp_fwd = 0;

  /* "pysamstats.pyx":1249
 *     cdef unsigned int reads_mapq0_pp = 0
 *     cdef unsigned int reads_mapq0_pp_fwd = 0
 *     cdef unsigned int reads_mapq0_pp_rev = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_reads_mapq0_pp_rev = 0;

  /* "pysamstats.pyx":1252
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1252; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":1253
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":1256
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1256; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1257
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":1260
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":1261
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":1262
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":1263
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":1264
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         mapq = aln.core.qual
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":1265
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)             # <<<<<<<<<<<<<<
 *         mapq = aln.core.qual
 *         mapq_squared = mapq**2
 */
    __pyx_v_is_reverse = ((int)(__pyx_v_flag & 16));

    /* "pysamstats.pyx":1266
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         mapq = aln.core.qual             # <<<<<<<<<<<<<<
 *         mapq_squared = mapq**2
 * 
 */
    __pyx_t_9 = __pyx_v_aln->core.qual;
    __pyx_v_mapq = __pyx_t_9;

    /* "pysamstats.pyx":1267
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 *         mapq = aln.core.qual
 *         mapq_squared = mapq**2             # <<<<<<<<<<<<<<
 * 
 *         mapq_squared_sum += mapq_squared
 */
    __pyx_v_mapq_squared = __Pyx_pow_uint64_t(__pyx_v_mapq, 2);

    /* "pysamstats.pyx":1269
 *         mapq_squared = mapq**2
 * 
 *         mapq_squared_sum += mapq_squared             # <<<<<<<<<<<<<<
 *         if mapq > mapq_max:
 *             mapq_max = mapq
 */
    __pyx_v_mapq_squared_sum = (__pyx_v_mapq_squared_sum + __pyx_v_mapq_squared);

    /* "pysamstats.pyx":1270
 * 
 *         mapq_squared_sum += mapq_squared
 *         if mapq > mapq_max:             # <<<<<<<<<<<<<<
 *             mapq_max = mapq
 *         if is_reverse:
 */
    __pyx_t_10 = (__pyx_v_mapq > __pyx_v_mapq_max);
    if (__pyx_t_10) {

      /* "pysamstats.pyx":1271
 *         mapq_squared_sum += mapq_squared
 *         if mapq > mapq_max:
 *             mapq_max = mapq             # <<<<<<<<<<<<<<
 *         if is_reverse:
 *             reads_rev += 1
 */
      __pyx_v_mapq_max = __pyx_v_mapq;
      goto __pyx_L5;
    }
    __pyx_L5:;

    /* "pysamstats.pyx":1272
 *         if mapq > mapq_max:
 *             mapq_max = mapq
 *         if is_reverse:             # <<<<<<<<<<<<<<
 *             reads_rev += 1
 *             mapq_rev_squared_sum += mapq_squared
 */
    if (__pyx_v_is_reverse) {

      /* "pysamstats.pyx":1273
 *             mapq_max = mapq
 *         if is_reverse:
 *             reads_rev += 1             # <<<<<<<<<<<<<<
 *             mapq_rev_squared_sum += mapq_squared
 *             if mapq > mapq_rev_max:
 */
      __pyx_v_reads_rev = (__pyx_v_reads_rev + 1);

      /* "pysamstats.pyx":1274
 *         if is_reverse:
 *             reads_rev += 1
 *             mapq_rev_squared_sum += mapq_squared             # <<<<<<<<<<<<<<
 *             if mapq > mapq_rev_max:
 *                 mapq_rev_max = mapq
 */
      __pyx_v_mapq_rev_squared_sum = (__pyx_v_mapq_rev_squared_sum + __pyx_v_mapq_squared);

      /* "pysamstats.pyx":1275
 *             reads_rev += 1
 *             mapq_rev_squared_sum += mapq_squared
 *             if mapq > mapq_rev_max:             # <<<<<<<<<<<<<<
 *                 mapq_rev_max = mapq
 *         else:
 */
      __pyx_t_10 = (__pyx_v_mapq > __pyx_v_mapq_rev_max);
      if (__pyx_t_10) {

        /* "pysamstats.pyx":1276
 *             mapq_rev_squared_sum += mapq_squared
 *             if mapq > mapq_rev_max:
 *                 mapq_rev_max = mapq             # <<<<<<<<<<<<<<
 *         else:
 *             reads_fwd += 1
 */
        __pyx_v_mapq_rev_max = __pyx_v_mapq;
        goto __pyx_L7;
      }
      __pyx_L7:;
      goto __pyx_L6;
    }
    /*else*/ {

      /* "pysamstats.pyx":1278
 *                 mapq_rev_max = mapq
 *         else:
 *             reads_fwd += 1             # <<<<<<<<<<<<<<
 *             mapq_fwd_squared_sum += mapq_squared
 *             if mapq > mapq_fwd_max:
 */
      __pyx_v_reads_fwd = (__pyx_v_reads_fwd + 1);

      /* "pysamstats.pyx":1279
 *         else:
 *             reads_fwd += 1
 *             mapq_fwd_squared_sum += mapq_squared             # <<<<<<<<<<<<<<
 *             if mapq > mapq_fwd_max:
 *                 mapq_fwd_max = mapq
 */
      __pyx_v_mapq_fwd_squared_sum = (__pyx_v_mapq_fwd_squared_sum + __pyx_v_mapq_squared);

      /* "pysamstats.pyx":1280
 *             reads_fwd += 1
 *             mapq_fwd_squared_sum += mapq_squared
 *             if mapq > mapq_fwd_max:             # <<<<<<<<<<<<<<
 *                 mapq_fwd_max = mapq
 * 
 */
      __pyx_t_10 = (__pyx_v_mapq > __pyx_v_mapq_fwd_max);
      if (__pyx_t_10) {

        /* "pysamstats.pyx":1281
 *             mapq_fwd_squared_sum += mapq_squared
 *             if mapq > mapq_fwd_max:
 *                 mapq_fwd_max = mapq             # <<<<<<<<<<<<<<
 * 
 *         if mapq == 0:
 */
        __pyx_v_mapq_fwd_max = __pyx_v_mapq;
        goto __pyx_L8;
      }
      __pyx_L8:;
    }
    __pyx_L6:;

    /* "pysamstats.pyx":1283
 *                 mapq_fwd_max = mapq
 * 
 *         if mapq == 0:             # <<<<<<<<<<<<<<
 *             reads_mapq0 += 1
 *             if is_reverse:
 */
    __pyx_t_10 = (__pyx_v_mapq == 0);
    if (__pyx_t_10) {

      /* "pysamstats.pyx":1284
 * 
 *         if mapq == 0:
 *             reads_mapq0 += 1             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_mapq0_rev += 1
 */
      __pyx_v_reads_mapq0 = (__pyx_v_reads_mapq0 + 1);

      /* "pysamstats.pyx":1285
 *         if mapq == 0:
 *             reads_mapq0 += 1
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_mapq0_rev += 1
 *             else:
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":1286
 *             reads_mapq0 += 1
 *             if is_reverse:
 *                 reads_mapq0_rev += 1             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_mapq0_fwd += 1
 */
        __pyx_v_reads_mapq0_rev = (__pyx_v_reads_mapq0_rev + 1);
        goto __pyx_L10;
      }
      /*else*/ {

        /* "pysamstats.pyx":1288
 *                 reads_mapq0_rev += 1
 *             else:
 *                 reads_mapq0_fwd += 1             # <<<<<<<<<<<<<<
 * 
 *         if is_proper_pair:
 */
        __pyx_v_reads_mapq0_fwd = (__pyx_v_reads_mapq0_fwd + 1);
      }
      __pyx_L10:;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "pysamstats.pyx":1290
 *                 reads_mapq0_fwd += 1
 * 
 *         if is_proper_pair:             # <<<<<<<<<<<<<<
 *             reads_pp += 1
 *             mapq_pp_squared_sum += mapq_squared
 */
    if (__pyx_v_is_proper_pair) {

      /* "pysamstats.pyx":1291
 * 
 *         if is_proper_pair:
 *             reads_pp += 1             # <<<<<<<<<<<<<<
 *             mapq_pp_squared_sum += mapq_squared
 *             if mapq > mapq_pp_max:
 */
      __pyx_v_reads_pp = (__pyx_v_reads_pp + 1);

      /* "pysamstats.pyx":1292
 *         if is_proper_pair:
 *             reads_pp += 1
 *             mapq_pp_squared_sum += mapq_squared             # <<<<<<<<<<<<<<
 *             if mapq > mapq_pp_max:
 *                 mapq_pp_max = mapq
 */
      __pyx_v_mapq_pp_squared_sum = (__pyx_v_mapq_pp_squared_sum + __pyx_v_mapq_squared);

      /* "pysamstats.pyx":1293
 *             reads_pp += 1
 *             mapq_pp_squared_sum += mapq_squared
 *             if mapq > mapq_pp_max:             # <<<<<<<<<<<<<<
 *                 mapq_pp_max = mapq
 *             if is_reverse:
 */
      __pyx_t_10 = (__pyx_v_mapq > __pyx_v_mapq_pp_max);
      if (__pyx_t_10) {

        /* "pysamstats.pyx":1294
 *             mapq_pp_squared_sum += mapq_squared
 *             if mapq > mapq_pp_max:
 *                 mapq_pp_max = mapq             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_pp_rev += 1
 */
        __pyx_v_mapq_pp_max = __pyx_v_mapq;
        goto __pyx_L12;
      }
      __pyx_L12:;

      /* "pysamstats.pyx":1295
 *             if mapq > mapq_pp_max:
 *                 mapq_pp_max = mapq
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_pp_rev += 1
 *                 mapq_pp_rev_squared_sum += mapq_squared
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":1296
 *                 mapq_pp_max = mapq
 *             if is_reverse:
 *                 reads_pp_rev += 1             # <<<<<<<<<<<<<<
 *                 mapq_pp_rev_squared_sum += mapq_squared
 *                 if mapq > mapq_pp_rev_max:
 */
        __pyx_v_reads_pp_rev = (__pyx_v_reads_pp_rev + 1);

        /* "pysamstats.pyx":1297
 *             if is_reverse:
 *                 reads_pp_rev += 1
 *                 mapq_pp_rev_squared_sum += mapq_squared             # <<<<<<<<<<<<<<
 *                 if mapq > mapq_pp_rev_max:
 *                     mapq_pp_rev_max = mapq
 */
        __pyx_v_mapq_pp_rev_squared_sum = (__pyx_v_mapq_pp_rev_squared_sum + __pyx_v_mapq_squared);

        /* "pysamstats.pyx":1298
 *                 reads_pp_rev += 1
 *                 mapq_pp_rev_squared_sum += mapq_squared
 *                 if mapq > mapq_pp_rev_max:             # <<<<<<<<<<<<<<
 *                     mapq_pp_rev_max = mapq
 *             else:
 */
        __pyx_t_10 = (__pyx_v_mapq > __pyx_v_mapq_pp_rev_max);
        if (__pyx_t_10) {

          /* "pysamstats.pyx":1299
 *                 mapq_pp_rev_squared_sum += mapq_squared
 *                 if mapq > mapq_pp_rev_max:
 *                     mapq_pp_rev_max = mapq             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_pp_fwd += 1
 */
          __pyx_v_mapq_pp_rev_max = __pyx_v_mapq;
          goto __pyx_L14;
        }
        __pyx_L14:;
        goto __pyx_L13;
      }
      /*else*/ {

        /* "pysamstats.pyx":1301
 *                     mapq_pp_rev_max = mapq
 *             else:
 *                 reads_pp_fwd += 1             # <<<<<<<<<<<<<<
 *                 mapq_pp_fwd_squared_sum += mapq_squared
 *                 if mapq > mapq_pp_fwd_max:
 */
        __pyx_v_reads_pp_fwd = (__pyx_v_reads_pp_fwd + 1);

        /* "pysamstats.pyx":1302
 *             else:
 *                 reads_pp_fwd += 1
 *                 mapq_pp_fwd_squared_sum += mapq_squared             # <<<<<<<<<<<<<<
 *                 if mapq > mapq_pp_fwd_max:
 *                     mapq_pp_fwd_max = mapq
 */
        __pyx_v_mapq_pp_fwd_squared_sum = (__pyx_v_mapq_pp_fwd_squared_sum + __pyx_v_mapq_squared);

        /* "pysamstats.pyx":1303
 *                 reads_pp_fwd += 1
 *                 mapq_pp_fwd_squared_sum += mapq_squared
 *                 if mapq > mapq_pp_fwd_max:             # <<<<<<<<<<<<<<
 *                     mapq_pp_fwd_max = mapq
 *             if mapq == 0:
 */
        __pyx_t_10 = (__pyx_v_mapq > __pyx_v_mapq_pp_fwd_max);
        if (__pyx_t_10) {

          /* "pysamstats.pyx":1304
 *                 mapq_pp_fwd_squared_sum += mapq_squared
 *                 if mapq > mapq_pp_fwd_max:
 *                     mapq_pp_fwd_max = mapq             # <<<<<<<<<<<<<<
 *             if mapq == 0:
 *                 reads_mapq0_pp += 1
 */
          __pyx_v_mapq_pp_fwd_max = __pyx_v_mapq;
          goto __pyx_L15;
        }
        __pyx_L15:;
      }
      __pyx_L13:;

      /* "pysamstats.pyx":1305
 *                 if mapq > mapq_pp_fwd_max:
 *                     mapq_pp_fwd_max = mapq
 *             if mapq == 0:             # <<<<<<<<<<<<<<
 *                 reads_mapq0_pp += 1
 *                 if is_reverse:
 */
      __pyx_t_10 = (__pyx_v_mapq == 0);
      if (__pyx_t_10) {

        /* "pysamstats.pyx":1306
 *                     mapq_pp_fwd_max = mapq
 *             if mapq == 0:
 *                 reads_mapq0_pp += 1             # <<<<<<<<<<<<<<
 *                 if is_reverse:
 *                     reads_mapq0_pp_rev += 1
 */
        __pyx_v_reads_mapq0_pp = (__pyx_v_reads_mapq0_pp + 1);

        /* "pysamstats.pyx":1307
 *             if mapq == 0:
 *                 reads_mapq0_pp += 1
 *                 if is_reverse:             # <<<<<<<<<<<<<<
 *                     reads_mapq0_pp_rev += 1
 *                 else:
 */
        if (__pyx_v_is_reverse) {

          /* "pysamstats.pyx":1308
 *                 reads_mapq0_pp += 1
 *                 if is_reverse:
 *                     reads_mapq0_pp_rev += 1             # <<<<<<<<<<<<<<
 *                 else:
 *                     reads_mapq0_pp_fwd += 1
 */
          __pyx_v_reads_mapq0_pp_rev = (__pyx_v_reads_mapq0_pp_rev + 1);
          goto __pyx_L17;
        }
        /*else*/ {

          /* "pysamstats.pyx":1310
 *                     reads_mapq0_pp_rev += 1
 *                 else:
 *                     reads_mapq0_pp_fwd += 1             # <<<<<<<<<<<<<<
 * 
 *     # construct output variables
 */
          __pyx_v_reads_mapq0_pp_fwd = (__pyx_v_reads_mapq0_pp_fwd + 1);
        }
        __pyx_L17:;
        goto __pyx_L16;
      }
      __pyx_L16:;
      goto __pyx_L11;
    }
    __pyx_L11:;
  }

  /* "pysamstats.pyx":1313
 * 
 *     # construct output variables
 *     rms_mapq = int(round(sqrt(mapq_squared_sum * 1. / n)))             # <<<<<<<<<<<<<<
 *     max_mapq = mapq_max
 *     if reads_rev > 0:
 */
  __pyx_t_11 = (__pyx_v_mapq_squared_sum * 1.);
  if (unlikely(__pyx_v_n == 0)) {
    PyErr_Format(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_11 / __pyx_v_n))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1313; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1313; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1313; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_rms_mapq = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1314
 *     # construct output variables
 *     rms_mapq = int(round(sqrt(mapq_squared_sum * 1. / n)))
 *     max_mapq = mapq_max             # <<<<<<<<<<<<<<
 *     if reads_rev > 0:
 *         rms_mapq_rev = int(round(sqrt(mapq_rev_squared_sum * 1. / reads_rev)))
 */
  __pyx_v_max_mapq = __pyx_v_mapq_max;

  /* "pysamstats.pyx":1315
 *     rms_mapq = int(round(sqrt(mapq_squared_sum * 1. / n)))
 *     max_mapq = mapq_max
 *     if reads_rev > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_rev = int(round(sqrt(mapq_rev_squared_sum * 1. / reads_rev)))
 *         max_mapq_rev = mapq_rev_max
 */
  __pyx_t_10 = (__pyx_v_reads_rev > 0);
  if (__pyx_t_10) {

    /* "pysamstats.pyx":1316
 *     max_mapq = mapq_max
 *     if reads_rev > 0:
 *         rms_mapq_rev = int(round(sqrt(mapq_rev_squared_sum * 1. / reads_rev)))             # <<<<<<<<<<<<<<
 *         max_mapq_rev = mapq_rev_max
 *     else:
 */
    __pyx_t_11 = (__pyx_v_mapq_rev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_rev == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_11 / __pyx_v_reads_rev))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1316; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1316; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1316; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_mapq_rev = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1317
 *     if reads_rev > 0:
 *         rms_mapq_rev = int(round(sqrt(mapq_rev_squared_sum * 1. / reads_rev)))
 *         max_mapq_rev = mapq_rev_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_rev = max_mapq_rev = 'NA'
 */
    __pyx_t_4 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_mapq_rev_max); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1317; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_max_mapq_rev = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L18;
  }
  /*else*/ {

    /* "pysamstats.pyx":1319
 *         max_mapq_rev = mapq_rev_max
 *     else:
 *         rms_mapq_rev = max_mapq_rev = 'NA'             # <<<<<<<<<<<<<<
 *     if reads_fwd > 0:
 *         rms_mapq_fwd = int(round(sqrt(mapq_fwd_squared_sum * 1. / reads_fwd)))
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_mapq_rev = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_max_mapq_rev = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L18:;

  /* "pysamstats.pyx":1320
 *     else:
 *         rms_mapq_rev = max_mapq_rev = 'NA'
 *     if reads_fwd > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_fwd = int(round(sqrt(mapq_fwd_squared_sum * 1. / reads_fwd)))
 *         max_mapq_fwd = mapq_fwd_max
 */
  __pyx_t_10 = (__pyx_v_reads_fwd > 0);
  if (__pyx_t_10) {

    /* "pysamstats.pyx":1321
 *         rms_mapq_rev = max_mapq_rev = 'NA'
 *     if reads_fwd > 0:
 *         rms_mapq_fwd = int(round(sqrt(mapq_fwd_squared_sum * 1. / reads_fwd)))             # <<<<<<<<<<<<<<
 *         max_mapq_fwd = mapq_fwd_max
 *     else:
 */
    __pyx_t_11 = (__pyx_v_mapq_fwd_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_fwd == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_11 / __pyx_v_reads_fwd))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1321; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1321; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_mapq_fwd = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1322
 *     if reads_fwd > 0:
 *         rms_mapq_fwd = int(round(sqrt(mapq_fwd_squared_sum * 1. / reads_fwd)))
 *         max_mapq_fwd = mapq_fwd_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_fwd = max_mapq_fwd = 'NA'
 */
    __pyx_t_4 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_mapq_fwd_max); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1322; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_max_mapq_fwd = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L19;
  }
  /*else*/ {

    /* "pysamstats.pyx":1324
 *         max_mapq_fwd = mapq_fwd_max
 *     else:
 *         rms_mapq_fwd = max_mapq_fwd = 'NA'             # <<<<<<<<<<<<<<
 *     if reads_pp > 0:
 *         rms_mapq_pp = int(round(sqrt(mapq_pp_squared_sum * 1. / reads_pp)))
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_mapq_fwd = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_max_mapq_fwd = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L19:;

  /* "pysamstats.pyx":1325
 *     else:
 *         rms_mapq_fwd = max_mapq_fwd = 'NA'
 *     if reads_pp > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_pp = int(round(sqrt(mapq_pp_squared_sum * 1. / reads_pp)))
 *         max_mapq_pp = mapq_pp_max
 */
  __pyx_t_10 = (__pyx_v_reads_pp > 0);
  if (__pyx_t_10) {

    /* "pysamstats.pyx":1326
 *         rms_mapq_fwd = max_mapq_fwd = 'NA'
 *     if reads_pp > 0:
 *         rms_mapq_pp = int(round(sqrt(mapq_pp_squared_sum * 1. / reads_pp)))             # <<<<<<<<<<<<<<
 *         max_mapq_pp = mapq_pp_max
 *     else:
 */
    __pyx_t_11 = (__pyx_v_mapq_pp_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_11 / __pyx_v_reads_pp))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_mapq_pp = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1327
 *     if reads_pp > 0:
 *         rms_mapq_pp = int(round(sqrt(mapq_pp_squared_sum * 1. / reads_pp)))
 *         max_mapq_pp = mapq_pp_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_pp = max_mapq_pp = 'NA'
 */
    __pyx_t_4 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_mapq_pp_max); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_max_mapq_pp = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L20;
  }
  /*else*/ {

    /* "pysamstats.pyx":1329
 *         max_mapq_pp = mapq_pp_max
 *     else:
 *         rms_mapq_pp = max_mapq_pp = 'NA'             # <<<<<<<<<<<<<<
 *     if reads_pp_fwd > 0:
 *         rms_mapq_pp_fwd = int(round(sqrt(mapq_pp_fwd_squared_sum * 1. / reads_pp_fwd)))
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_mapq_pp = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_max_mapq_pp = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L20:;

  /* "pysamstats.pyx":1330
 *     else:
 *         rms_mapq_pp = max_mapq_pp = 'NA'
 *     if reads_pp_fwd > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_pp_fwd = int(round(sqrt(mapq_pp_fwd_squared_sum * 1. / reads_pp_fwd)))
 *         max_mapq_pp_fwd = mapq_pp_fwd_max
 */
  __pyx_t_10 = (__pyx_v_reads_pp_fwd > 0);
  if (__pyx_t_10) {

    /* "pysamstats.pyx":1331
 *         rms_mapq_pp = max_mapq_pp = 'NA'
 *     if reads_pp_fwd > 0:
 *         rms_mapq_pp_fwd = int(round(sqrt(mapq_pp_fwd_squared_sum * 1. / reads_pp_fwd)))             # <<<<<<<<<<<<<<
 *         max_mapq_pp_fwd = mapq_pp_fwd_max
 *     else:
 */
    __pyx_t_11 = (__pyx_v_mapq_pp_fwd_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp_fwd == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_11 / __pyx_v_reads_pp_fwd))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1331; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1331; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1331; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_mapq_pp_fwd = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1332
 *     if reads_pp_fwd > 0:
 *         rms_mapq_pp_fwd = int(round(sqrt(mapq_pp_fwd_squared_sum * 1. / reads_pp_fwd)))
 *         max_mapq_pp_fwd = mapq_pp_fwd_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_pp_fwd = max_mapq_pp_fwd = 'NA'
 */
    __pyx_t_4 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_mapq_pp_fwd_max); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1332; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_max_mapq_pp_fwd = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L21;
  }
  /*else*/ {

    /* "pysamstats.pyx":1334
 *         max_mapq_pp_fwd = mapq_pp_fwd_max
 *     else:
 *         rms_mapq_pp_fwd = max_mapq_pp_fwd = 'NA'             # <<<<<<<<<<<<<<
 *     if reads_pp_rev > 0:
 *         rms_mapq_pp_rev = int(round(sqrt(mapq_pp_rev_squared_sum * 1. / reads_pp_rev)))
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_mapq_pp_fwd = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_max_mapq_pp_fwd = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L21:;

  /* "pysamstats.pyx":1335
 *     else:
 *         rms_mapq_pp_fwd = max_mapq_pp_fwd = 'NA'
 *     if reads_pp_rev > 0:             # <<<<<<<<<<<<<<
 *         rms_mapq_pp_rev = int(round(sqrt(mapq_pp_rev_squared_sum * 1. / reads_pp_rev)))
 *         max_mapq_pp_rev = mapq_pp_rev_max
 */
  __pyx_t_10 = (__pyx_v_reads_pp_rev > 0);
  if (__pyx_t_10) {

    /* "pysamstats.pyx":1336
 *         rms_mapq_pp_fwd = max_mapq_pp_fwd = 'NA'
 *     if reads_pp_rev > 0:
 *         rms_mapq_pp_rev = int(round(sqrt(mapq_pp_rev_squared_sum * 1. / reads_pp_rev)))             # <<<<<<<<<<<<<<
 *         max_mapq_pp_rev = mapq_pp_rev_max
 *     else:
 */
    __pyx_t_11 = (__pyx_v_mapq_pp_rev_squared_sum * 1.);
    if (unlikely(__pyx_v_reads_pp_rev == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = PyFloat_FromDouble(sqrt((__pyx_t_11 / __pyx_v_reads_pp_rev))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __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 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __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 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1336; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
    __pyx_v_rms_mapq_pp_rev = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1337
 *     if reads_pp_rev > 0:
 *         rms_mapq_pp_rev = int(round(sqrt(mapq_pp_rev_squared_sum * 1. / reads_pp_rev)))
 *         max_mapq_pp_rev = mapq_pp_rev_max             # <<<<<<<<<<<<<<
 *     else:
 *         rms_mapq_pp_rev = max_mapq_pp_rev = 'NA'
 */
    __pyx_t_4 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_mapq_pp_rev_max); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1337; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_max_mapq_pp_rev = __pyx_t_4;
    __pyx_t_4 = 0;
    goto __pyx_L22;
  }
  /*else*/ {

    /* "pysamstats.pyx":1339
 *         max_mapq_pp_rev = mapq_pp_rev_max
 *     else:
 *         rms_mapq_pp_rev = max_mapq_pp_rev = 'NA'             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom,
 */
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_rms_mapq_pp_rev = ((PyObject *)__pyx_n_s__NA);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_v_max_mapq_pp_rev = ((PyObject *)__pyx_n_s__NA);
  }
  __pyx_L22:;

  /* "pysamstats.pyx":1341
 *         rms_mapq_pp_rev = max_mapq_pp_rev = 'NA'
 * 
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *             'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1342
 * 
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1342; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1343
 *     return {'chrom': chrom,
 *             'pos': pos,
 *             'reads_all': n,             # <<<<<<<<<<<<<<
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_n); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_all), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1344
 *             'pos': pos,
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,             # <<<<<<<<<<<<<<
 *             'reads_rev': reads_rev,
 *             'reads_pp': reads_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1345
 *             'reads_all': n,
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,             # <<<<<<<<<<<<<<
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1346
 *             'reads_fwd': reads_fwd,
 *             'reads_rev': reads_rev,
 *             'reads_pp': reads_pp,             # <<<<<<<<<<<<<<
 *             'reads_pp_fwd': reads_pp_fwd,
 *             'reads_pp_rev': reads_pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1347
 *             'reads_rev': reads_rev,
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,             # <<<<<<<<<<<<<<
 *             'reads_pp_rev': reads_pp_rev,
 *             'reads_mapq0': reads_mapq0,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1347; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1348
 *             'reads_pp': reads_pp,
 *             'reads_pp_fwd': reads_pp_fwd,
 *             'reads_pp_rev': reads_pp_rev,             # <<<<<<<<<<<<<<
 *             'reads_mapq0': reads_mapq0,
 *             'reads_mapq0_fwd': reads_mapq0_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1348; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1349
 *             'reads_pp_fwd': reads_pp_fwd,
 *             'reads_pp_rev': reads_pp_rev,
 *             'reads_mapq0': reads_mapq0,             # <<<<<<<<<<<<<<
 *             'reads_mapq0_fwd': reads_mapq0_fwd,
 *             'reads_mapq0_rev': reads_mapq0_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mapq0); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1349; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_mapq0), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1350
 *             'reads_pp_rev': reads_pp_rev,
 *             'reads_mapq0': reads_mapq0,
 *             'reads_mapq0_fwd': reads_mapq0_fwd,             # <<<<<<<<<<<<<<
 *             'reads_mapq0_rev': reads_mapq0_rev,
 *             'reads_mapq0_pp': reads_mapq0_pp,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mapq0_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1350; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_mapq0_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1351
 *             'reads_mapq0': reads_mapq0,
 *             'reads_mapq0_fwd': reads_mapq0_fwd,
 *             'reads_mapq0_rev': reads_mapq0_rev,             # <<<<<<<<<<<<<<
 *             'reads_mapq0_pp': reads_mapq0_pp,
 *             'reads_mapq0_pp_fwd': reads_mapq0_pp_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mapq0_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1351; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_mapq0_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1352
 *             'reads_mapq0_fwd': reads_mapq0_fwd,
 *             'reads_mapq0_rev': reads_mapq0_rev,
 *             'reads_mapq0_pp': reads_mapq0_pp,             # <<<<<<<<<<<<<<
 *             'reads_mapq0_pp_fwd': reads_mapq0_pp_fwd,
 *             'reads_mapq0_pp_rev': reads_mapq0_pp_rev,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mapq0_pp); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_mapq0_pp), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1353
 *             'reads_mapq0_rev': reads_mapq0_rev,
 *             'reads_mapq0_pp': reads_mapq0_pp,
 *             'reads_mapq0_pp_fwd': reads_mapq0_pp_fwd,             # <<<<<<<<<<<<<<
 *             'reads_mapq0_pp_rev': reads_mapq0_pp_rev,
 *             'rms_mapq': rms_mapq,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mapq0_pp_fwd); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_mapq0_pp_fwd), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1354
 *             'reads_mapq0_pp': reads_mapq0_pp,
 *             'reads_mapq0_pp_fwd': reads_mapq0_pp_fwd,
 *             'reads_mapq0_pp_rev': reads_mapq0_pp_rev,             # <<<<<<<<<<<<<<
 *             'rms_mapq': rms_mapq,
 *             'rms_mapq_fwd': rms_mapq_fwd,
 */
  __pyx_t_5 = PyLong_FromUnsignedLong(__pyx_v_reads_mapq0_pp_rev); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1354; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_mapq0_pp_rev), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1355
 *             'reads_mapq0_pp_fwd': reads_mapq0_pp_fwd,
 *             'reads_mapq0_pp_rev': reads_mapq0_pp_rev,
 *             'rms_mapq': rms_mapq,             # <<<<<<<<<<<<<<
 *             'rms_mapq_fwd': rms_mapq_fwd,
 *             'rms_mapq_rev': rms_mapq_rev,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_mapq), __pyx_v_rms_mapq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1356
 *             'reads_mapq0_pp_rev': reads_mapq0_pp_rev,
 *             'rms_mapq': rms_mapq,
 *             'rms_mapq_fwd': rms_mapq_fwd,             # <<<<<<<<<<<<<<
 *             'rms_mapq_rev': rms_mapq_rev,
 *             'rms_mapq_pp': rms_mapq_pp,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_mapq_fwd), __pyx_v_rms_mapq_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1357
 *             'rms_mapq': rms_mapq,
 *             'rms_mapq_fwd': rms_mapq_fwd,
 *             'rms_mapq_rev': rms_mapq_rev,             # <<<<<<<<<<<<<<
 *             'rms_mapq_pp': rms_mapq_pp,
 *             'rms_mapq_pp_fwd': rms_mapq_pp_fwd,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_mapq_rev), __pyx_v_rms_mapq_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1358
 *             'rms_mapq_fwd': rms_mapq_fwd,
 *             'rms_mapq_rev': rms_mapq_rev,
 *             'rms_mapq_pp': rms_mapq_pp,             # <<<<<<<<<<<<<<
 *             'rms_mapq_pp_fwd': rms_mapq_pp_fwd,
 *             'rms_mapq_pp_rev': rms_mapq_pp_rev,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_mapq_pp), __pyx_v_rms_mapq_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1359
 *             'rms_mapq_rev': rms_mapq_rev,
 *             'rms_mapq_pp': rms_mapq_pp,
 *             'rms_mapq_pp_fwd': rms_mapq_pp_fwd,             # <<<<<<<<<<<<<<
 *             'rms_mapq_pp_rev': rms_mapq_pp_rev,
 *             'max_mapq': max_mapq,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_mapq_pp_fwd), __pyx_v_rms_mapq_pp_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1360
 *             'rms_mapq_pp': rms_mapq_pp,
 *             'rms_mapq_pp_fwd': rms_mapq_pp_fwd,
 *             'rms_mapq_pp_rev': rms_mapq_pp_rev,             # <<<<<<<<<<<<<<
 *             'max_mapq': max_mapq,
 *             'max_mapq_fwd': max_mapq_fwd,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_mapq_pp_rev), __pyx_v_rms_mapq_pp_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1361
 *             'rms_mapq_pp_fwd': rms_mapq_pp_fwd,
 *             'rms_mapq_pp_rev': rms_mapq_pp_rev,
 *             'max_mapq': max_mapq,             # <<<<<<<<<<<<<<
 *             'max_mapq_fwd': max_mapq_fwd,
 *             'max_mapq_rev': max_mapq_rev,
 */
  __pyx_t_5 = __Pyx_PyInt_to_py_uint64_t(__pyx_v_max_mapq); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__max_mapq), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1362
 *             'rms_mapq_pp_rev': rms_mapq_pp_rev,
 *             'max_mapq': max_mapq,
 *             'max_mapq_fwd': max_mapq_fwd,             # <<<<<<<<<<<<<<
 *             'max_mapq_rev': max_mapq_rev,
 *             'max_mapq_pp': max_mapq_pp,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__max_mapq_fwd), __pyx_v_max_mapq_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1363
 *             'max_mapq': max_mapq,
 *             'max_mapq_fwd': max_mapq_fwd,
 *             'max_mapq_rev': max_mapq_rev,             # <<<<<<<<<<<<<<
 *             'max_mapq_pp': max_mapq_pp,
 *             'max_mapq_pp_fwd': max_mapq_pp_fwd,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__max_mapq_rev), __pyx_v_max_mapq_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1364
 *             'max_mapq_fwd': max_mapq_fwd,
 *             'max_mapq_rev': max_mapq_rev,
 *             'max_mapq_pp': max_mapq_pp,             # <<<<<<<<<<<<<<
 *             'max_mapq_pp_fwd': max_mapq_pp_fwd,
 *             'max_mapq_pp_rev': max_mapq_pp_rev,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__max_mapq_pp), __pyx_v_max_mapq_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1365
 *             'max_mapq_rev': max_mapq_rev,
 *             'max_mapq_pp': max_mapq_pp,
 *             'max_mapq_pp_fwd': max_mapq_pp_fwd,             # <<<<<<<<<<<<<<
 *             'max_mapq_pp_rev': max_mapq_pp_rev,
 *             }
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__max_mapq_pp_fwd), __pyx_v_max_mapq_pp_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1366
 *             'max_mapq_pp': max_mapq_pp,
 *             'max_mapq_pp_fwd': max_mapq_pp_fwd,
 *             'max_mapq_pp_rev': max_mapq_pp_rev,             # <<<<<<<<<<<<<<
 *             }
 * 
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__max_mapq_pp_rev), __pyx_v_max_mapq_pp_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_mapq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_rms_mapq);
  __Pyx_XDECREF(__pyx_v_rms_mapq_rev);
  __Pyx_XDECREF(__pyx_v_max_mapq_rev);
  __Pyx_XDECREF(__pyx_v_rms_mapq_fwd);
  __Pyx_XDECREF(__pyx_v_max_mapq_fwd);
  __Pyx_XDECREF(__pyx_v_rms_mapq_pp);
  __Pyx_XDECREF(__pyx_v_max_mapq_pp);
  __Pyx_XDECREF(__pyx_v_rms_mapq_pp_fwd);
  __Pyx_XDECREF(__pyx_v_max_mapq_pp_fwd);
  __Pyx_XDECREF(__pyx_v_rms_mapq_pp_rev);
  __Pyx_XDECREF(__pyx_v_max_mapq_pp_rev);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_64construct_rec_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_64construct_rec_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_mapq_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__col,&__pyx_n_s__one_based,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__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_mapq_strand", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1211; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_mapq_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1211; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[1]);
    if (values[2]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1211; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1211
 * 
 * 
 * cpdef object construct_rec_mapq_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_mapq_strand", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1211; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_mapq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_63construct_rec_mapq_strand(__pyx_self, __pyx_v_samfile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_63construct_rec_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_mapq_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_mapq_strand", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_mapq_strand(__pyx_v_samfile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1211; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_mapq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_67generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_66stat_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_66stat_mapq_strand = {__Pyx_NAMESTR("stat_mapq_strand"), (PyCFunction)__pyx_pw_10pysamstats_66stat_mapq_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_66stat_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_mapq_strand (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__samfile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysamstats.pyx":1370
 * 
 * 
 * def stat_mapq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_32;
    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__chrom);
          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__one_based);
          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, "stat_mapq_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
    __pyx_v_one_based = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_mapq_strand", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_mapq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_65stat_mapq_strand(__pyx_self, __pyx_v_samfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_65stat_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_mapq_strand", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *)__pyx_ptype_10pysamstats___pyx_scope_struct_9_stat_mapq_strand->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_9_stat_mapq_strand, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_67generator9, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_mapq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_67generator9(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_mapq_strand __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1371
 * 
 * def stat_mapq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_mapq_strand(samfile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1371; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1372
 * def stat_mapq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_mapq_strand(samfile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 1372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1372; __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 = 1372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1372; __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 = 1372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1372; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":1373
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_mapq_strand(samfile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_mapq_strand(__pyx_cur_scope->__pyx_v_samfile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1373; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_mapq_strand", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_69write_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_69write_mapq_strand = {__Pyx_NAMESTR("write_mapq_strand"), (PyCFunction)__pyx_pw_10pysamstats_69write_mapq_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_69write_mapq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_mapq_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_mapq_strand", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_68write_mapq_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1376
 * 
 * 
 * def write_mapq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all', 'reads_fwd', 'reads_rev',
 */

static PyObject *__pyx_pf_10pysamstats_68write_mapq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_mapq_strand", 0);

  /* "pysamstats.pyx":1377
 * 
 * def write_mapq_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *                   'reads_all', 'reads_fwd', 'reads_rev',
 *                   'reads_pp', 'reads_pp_fwd', 'reads_pp_rev',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_33));
  __pyx_v_fieldnames = __pyx_k_tuple_33;

  /* "pysamstats.pyx":1387
 *                   'max_mapq_pp', 'max_mapq_pp_fwd', 'max_mapq_pp_rev',
 *                   )
 *     write_stats(stat_mapq_strand, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_mapq_strand); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1387; __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 = 1387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_mapq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1395
 * 
 * 
 * cpdef object construct_rec_baseq(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */

static PyObject *__pyx_pw_10pysamstats_71construct_rec_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_baseq(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_baseq *__pyx_optional_args) {
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  unsigned int __pyx_v_reads_nodel;
  unsigned int __pyx_v_reads_pp_nodel;
  uint64_t __pyx_v_baseq;
  uint64_t __pyx_v_baseq_squared;
  uint64_t __pyx_v_baseq_squared_sum;
  uint64_t __pyx_v_baseq_pp_squared_sum;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_v_rms_baseq = NULL;
  PyObject *__pyx_v_rms_baseq_pp = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_baseq", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":1405
 *     cdef uint32_t flag
 *     cdef bint is_proper_pair
 *     cdef unsigned int reads_nodel = 0             # <<<<<<<<<<<<<<
 * #    cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_nodel = 0
 */
  __pyx_v_reads_nodel = 0;

  /* "pysamstats.pyx":1407
 *     cdef unsigned int reads_nodel = 0
 * #    cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq, baseq_squared
 *     cdef uint64_t baseq_squared_sum = 0
 */
  __pyx_v_reads_pp_nodel = 0;

  /* "pysamstats.pyx":1409
 *     cdef unsigned int reads_pp_nodel = 0
 *     cdef uint64_t baseq, baseq_squared
 *     cdef uint64_t baseq_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_pp_squared_sum = 0
 * 
 */
  __pyx_v_baseq_squared_sum = 0;

  /* "pysamstats.pyx":1410
 *     cdef uint64_t baseq, baseq_squared
 *     cdef uint64_t baseq_squared_sum = 0
 *     cdef uint64_t baseq_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_baseq_pp_squared_sum = 0;

  /* "pysamstats.pyx":1413
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1413; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":1414
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":1417
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1417; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1418
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":1421
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":1422
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":1423
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":1424
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *  #       if is_proper_pair:
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":1425
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *  #       if is_proper_pair:
 *  #           reads_pp += 1
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":1429
 *  #           reads_pp += 1
 *         # N.B., base quality only makes sense if the aligned read is not a deletion
 *         if not read.is_del:             # <<<<<<<<<<<<<<
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]
 */
    __pyx_t_10 = (!__pyx_v_read->is_del);
    if (__pyx_t_10) {

      /* "pysamstats.pyx":1430
 *         # N.B., base quality only makes sense if the aligned read is not a deletion
 *         if not read.is_del:
 *             reads_nodel += 1             # <<<<<<<<<<<<<<
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 */
      __pyx_v_reads_nodel = (__pyx_v_reads_nodel + 1);

      /* "pysamstats.pyx":1431
 *         if not read.is_del:
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]             # <<<<<<<<<<<<<<
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 */
      __pyx_v_baseq = (bam1_qual(__pyx_v_aln)[__pyx_v_read->qpos]);

      /* "pysamstats.pyx":1432
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2             # <<<<<<<<<<<<<<
 *             baseq_squared_sum += baseq_squared
 *             if is_proper_pair:
 */
      __pyx_v_baseq_squared = __Pyx_pow_uint64_t(__pyx_v_baseq, 2);

      /* "pysamstats.pyx":1433
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1
 */
      __pyx_v_baseq_squared_sum = (__pyx_v_baseq_squared_sum + __pyx_v_baseq_squared);

      /* "pysamstats.pyx":1434
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared
 */
      if (__pyx_v_is_proper_pair) {

        /* "pysamstats.pyx":1435
 *             baseq_squared_sum += baseq_squared
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1             # <<<<<<<<<<<<<<
 *                 baseq_pp_squared_sum += baseq_squared
 * 
 */
        __pyx_v_reads_pp_nodel = (__pyx_v_reads_pp_nodel + 1);

        /* "pysamstats.pyx":1436
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 * 
 *     # output variables
 */
        __pyx_v_baseq_pp_squared_sum = (__pyx_v_baseq_pp_squared_sum + __pyx_v_baseq_squared);
        goto __pyx_L6;
      }
      __pyx_L6:;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  /* "pysamstats.pyx":1439
 * 
 *     # output variables
 *     rms_baseq = rootmean(baseq_squared_sum, reads_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 * 
 */
  __pyx_t_4 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_squared_sum, __pyx_v_reads_nodel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1439; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_rms_baseq = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1440
 *     # output variables
 *     rms_baseq = rootmean(baseq_squared_sum, reads_nodel)
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom,
 */
  __pyx_t_4 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_pp_squared_sum, __pyx_v_reads_pp_nodel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1440; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_rms_baseq_pp = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1442
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 * 
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 *  #           'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1443
 * 
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 *  #           'reads_all': n,
 *  #           'reads_pp': reads_pp,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1443; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1446
 *  #           'reads_all': n,
 *  #           'reads_pp': reads_pp,
 *             'rms_baseq': rms_baseq,             # <<<<<<<<<<<<<<
 *             'rms_baseq_pp': rms_baseq_pp}
 * 
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_baseq), __pyx_v_rms_baseq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1447
 *  #           'reads_pp': reads_pp,
 *             'rms_baseq': rms_baseq,
 *             'rms_baseq_pp': rms_baseq_pp}             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_baseq_pp), __pyx_v_rms_baseq_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1442; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_rms_baseq);
  __Pyx_XDECREF(__pyx_v_rms_baseq_pp);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_71construct_rec_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_71construct_rec_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_baseq (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__col,&__pyx_n_s__one_based,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__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_baseq", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_baseq") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[1]);
    if (values[2]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1395
 * 
 * 
 * cpdef object construct_rec_baseq(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_baseq", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_70construct_rec_baseq(__pyx_self, __pyx_v_samfile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_70construct_rec_baseq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_baseq __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_baseq", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_baseq(__pyx_v_samfile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_74generator10(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_73stat_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_73stat_baseq = {__Pyx_NAMESTR("stat_baseq"), (PyCFunction)__pyx_pw_10pysamstats_73stat_baseq, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_73stat_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_baseq (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__samfile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysamstats.pyx":1450
 * 
 * 
 * def stat_baseq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_34;
    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__chrom);
          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__one_based);
          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, "stat_baseq") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1450; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
    __pyx_v_one_based = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_baseq", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_72stat_baseq(__pyx_self, __pyx_v_samfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_72stat_baseq(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_baseq", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *)__pyx_ptype_10pysamstats___pyx_scope_struct_10_stat_baseq->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_10_stat_baseq, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_74generator10, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_74generator10(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_baseq __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 1450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1451
 * 
 * def stat_baseq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_baseq(samfile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1451; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1452
 * def stat_baseq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_baseq(samfile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); 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_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1452; __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 = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1452; __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 = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1452; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":1453
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_baseq(samfile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_baseq(__pyx_cur_scope->__pyx_v_samfile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1453; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_baseq", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_76write_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_76write_baseq = {__Pyx_NAMESTR("write_baseq"), (PyCFunction)__pyx_pw_10pysamstats_76write_baseq, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_76write_baseq(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_baseq (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_baseq", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_75write_baseq(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1456
 * 
 * 
 * def write_baseq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 * #                  'reads_all',
 */

static PyObject *__pyx_pf_10pysamstats_75write_baseq(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_baseq", 0);

  /* "pysamstats.pyx":1457
 * 
 * def write_baseq(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 * #                  'reads_all',
 * #                  'reads_pp',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_35));
  __pyx_v_fieldnames = __pyx_k_tuple_35;

  /* "pysamstats.pyx":1463
 *                   'rms_baseq_pp',
 *                   )
 *     write_stats(stat_baseq, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_baseq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1463; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_baseq", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1471
 * 
 * 
 * cpdef object construct_rec_baseq_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */

static PyObject *__pyx_pw_10pysamstats_78construct_rec_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_baseq_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_baseq_strand *__pyx_optional_args) {
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_is_reverse;
  uint64_t __pyx_v_baseq;
  uint64_t __pyx_v_baseq_squared;
  uint64_t __pyx_v_baseq_squared_sum;
  uint64_t __pyx_v_baseq_fwd_squared_sum;
  uint64_t __pyx_v_baseq_rev_squared_sum;
  uint64_t __pyx_v_baseq_pp_squared_sum;
  uint64_t __pyx_v_baseq_pp_fwd_squared_sum;
  uint64_t __pyx_v_baseq_pp_rev_squared_sum;
  unsigned int __pyx_v_reads_nodel;
  unsigned int __pyx_v_reads_rev_nodel;
  unsigned int __pyx_v_reads_fwd_nodel;
  unsigned int __pyx_v_reads_pp_nodel;
  unsigned int __pyx_v_reads_pp_rev_nodel;
  unsigned int __pyx_v_reads_pp_fwd_nodel;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_v_rms_baseq = NULL;
  PyObject *__pyx_v_rms_baseq_rev = NULL;
  PyObject *__pyx_v_rms_baseq_fwd = NULL;
  PyObject *__pyx_v_rms_baseq_pp = NULL;
  PyObject *__pyx_v_rms_baseq_pp_fwd = NULL;
  PyObject *__pyx_v_rms_baseq_pp_rev = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_baseq_strand", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":1486
 *     cdef uint64_t baseq_squared
 * 
 *     cdef uint64_t baseq_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_fwd_squared_sum = 0
 *     cdef uint64_t baseq_rev_squared_sum = 0
 */
  __pyx_v_baseq_squared_sum = 0;

  /* "pysamstats.pyx":1487
 * 
 *     cdef uint64_t baseq_squared_sum = 0
 *     cdef uint64_t baseq_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_rev_squared_sum = 0
 *     cdef uint64_t baseq_pp_squared_sum = 0
 */
  __pyx_v_baseq_fwd_squared_sum = 0;

  /* "pysamstats.pyx":1488
 *     cdef uint64_t baseq_squared_sum = 0
 *     cdef uint64_t baseq_fwd_squared_sum = 0
 *     cdef uint64_t baseq_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_pp_squared_sum = 0
 *     cdef uint64_t baseq_pp_fwd_squared_sum = 0
 */
  __pyx_v_baseq_rev_squared_sum = 0;

  /* "pysamstats.pyx":1489
 *     cdef uint64_t baseq_fwd_squared_sum = 0
 *     cdef uint64_t baseq_rev_squared_sum = 0
 *     cdef uint64_t baseq_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_pp_fwd_squared_sum = 0
 *     cdef uint64_t baseq_pp_rev_squared_sum = 0
 */
  __pyx_v_baseq_pp_squared_sum = 0;

  /* "pysamstats.pyx":1490
 *     cdef uint64_t baseq_rev_squared_sum = 0
 *     cdef uint64_t baseq_pp_squared_sum = 0
 *     cdef uint64_t baseq_pp_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_pp_rev_squared_sum = 0
 * 
 */
  __pyx_v_baseq_pp_fwd_squared_sum = 0;

  /* "pysamstats.pyx":1491
 *     cdef uint64_t baseq_pp_squared_sum = 0
 *     cdef uint64_t baseq_pp_fwd_squared_sum = 0
 *     cdef uint64_t baseq_pp_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 * 
 * #    cdef unsigned int reads_rev = 0
 */
  __pyx_v_baseq_pp_rev_squared_sum = 0;

  /* "pysamstats.pyx":1498
 * #    cdef unsigned int reads_pp_rev = 0
 * #    cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_rev_nodel = 0
 *     cdef unsigned int reads_fwd_nodel = 0
 */
  __pyx_v_reads_nodel = 0;

  /* "pysamstats.pyx":1499
 * #    cdef unsigned int reads_pp_fwd = 0
 *     cdef unsigned int reads_nodel = 0
 *     cdef unsigned int reads_rev_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_fwd_nodel = 0
 *     cdef unsigned int reads_pp_nodel = 0
 */
  __pyx_v_reads_rev_nodel = 0;

  /* "pysamstats.pyx":1500
 *     cdef unsigned int reads_nodel = 0
 *     cdef unsigned int reads_rev_nodel = 0
 *     cdef unsigned int reads_fwd_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_nodel = 0
 *     cdef unsigned int reads_pp_rev_nodel = 0
 */
  __pyx_v_reads_fwd_nodel = 0;

  /* "pysamstats.pyx":1501
 *     cdef unsigned int reads_rev_nodel = 0
 *     cdef unsigned int reads_fwd_nodel = 0
 *     cdef unsigned int reads_pp_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_rev_nodel = 0
 *     cdef unsigned int reads_pp_fwd_nodel = 0
 */
  __pyx_v_reads_pp_nodel = 0;

  /* "pysamstats.pyx":1502
 *     cdef unsigned int reads_fwd_nodel = 0
 *     cdef unsigned int reads_pp_nodel = 0
 *     cdef unsigned int reads_pp_rev_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_fwd_nodel = 0
 * 
 */
  __pyx_v_reads_pp_rev_nodel = 0;

  /* "pysamstats.pyx":1503
 *     cdef unsigned int reads_pp_nodel = 0
 *     cdef unsigned int reads_pp_rev_nodel = 0
 *     cdef unsigned int reads_pp_fwd_nodel = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_reads_pp_fwd_nodel = 0;

  /* "pysamstats.pyx":1506
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":1507
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":1510
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1511
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":1514
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":1515
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":1516
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":1517
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":1518
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 * 
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":1519
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)             # <<<<<<<<<<<<<<
 * 
 * #        if is_reverse:
 */
    __pyx_v_is_reverse = ((int)(__pyx_v_flag & 16));

    /* "pysamstats.pyx":1533
 * 
 *         # N.B., baseq only makes sense if not a deletion
 *         if not read.is_del:             # <<<<<<<<<<<<<<
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]
 */
    __pyx_t_10 = (!__pyx_v_read->is_del);
    if (__pyx_t_10) {

      /* "pysamstats.pyx":1534
 *         # N.B., baseq only makes sense if not a deletion
 *         if not read.is_del:
 *             reads_nodel += 1             # <<<<<<<<<<<<<<
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 */
      __pyx_v_reads_nodel = (__pyx_v_reads_nodel + 1);

      /* "pysamstats.pyx":1535
 *         if not read.is_del:
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]             # <<<<<<<<<<<<<<
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 */
      __pyx_v_baseq = (bam1_qual(__pyx_v_aln)[__pyx_v_read->qpos]);

      /* "pysamstats.pyx":1536
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2             # <<<<<<<<<<<<<<
 *             baseq_squared_sum += baseq_squared
 *             if is_reverse:
 */
      __pyx_v_baseq_squared = __Pyx_pow_uint64_t(__pyx_v_baseq, 2);

      /* "pysamstats.pyx":1537
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_rev_nodel += 1
 */
      __pyx_v_baseq_squared_sum = (__pyx_v_baseq_squared_sum + __pyx_v_baseq_squared);

      /* "pysamstats.pyx":1538
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_rev_nodel += 1
 *                 baseq_rev_squared_sum += baseq_squared
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":1539
 *             baseq_squared_sum += baseq_squared
 *             if is_reverse:
 *                 reads_rev_nodel += 1             # <<<<<<<<<<<<<<
 *                 baseq_rev_squared_sum += baseq_squared
 *             else:
 */
        __pyx_v_reads_rev_nodel = (__pyx_v_reads_rev_nodel + 1);

        /* "pysamstats.pyx":1540
 *             if is_reverse:
 *                 reads_rev_nodel += 1
 *                 baseq_rev_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_fwd_nodel += 1
 */
        __pyx_v_baseq_rev_squared_sum = (__pyx_v_baseq_rev_squared_sum + __pyx_v_baseq_squared);
        goto __pyx_L6;
      }
      /*else*/ {

        /* "pysamstats.pyx":1542
 *                 baseq_rev_squared_sum += baseq_squared
 *             else:
 *                 reads_fwd_nodel += 1             # <<<<<<<<<<<<<<
 *                 baseq_fwd_squared_sum += baseq_squared
 *             if is_proper_pair:
 */
        __pyx_v_reads_fwd_nodel = (__pyx_v_reads_fwd_nodel + 1);

        /* "pysamstats.pyx":1543
 *             else:
 *                 reads_fwd_nodel += 1
 *                 baseq_fwd_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1
 */
        __pyx_v_baseq_fwd_squared_sum = (__pyx_v_baseq_fwd_squared_sum + __pyx_v_baseq_squared);
      }
      __pyx_L6:;

      /* "pysamstats.pyx":1544
 *                 reads_fwd_nodel += 1
 *                 baseq_fwd_squared_sum += baseq_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared
 */
      if (__pyx_v_is_proper_pair) {

        /* "pysamstats.pyx":1545
 *                 baseq_fwd_squared_sum += baseq_squared
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1             # <<<<<<<<<<<<<<
 *                 baseq_pp_squared_sum += baseq_squared
 *                 if is_reverse:
 */
        __pyx_v_reads_pp_nodel = (__pyx_v_reads_pp_nodel + 1);

        /* "pysamstats.pyx":1546
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                 if is_reverse:
 *                     reads_pp_rev_nodel += 1
 */
        __pyx_v_baseq_pp_squared_sum = (__pyx_v_baseq_pp_squared_sum + __pyx_v_baseq_squared);

        /* "pysamstats.pyx":1547
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared
 *                 if is_reverse:             # <<<<<<<<<<<<<<
 *                     reads_pp_rev_nodel += 1
 *                     baseq_pp_rev_squared_sum += baseq_squared
 */
        if (__pyx_v_is_reverse) {

          /* "pysamstats.pyx":1548
 *                 baseq_pp_squared_sum += baseq_squared
 *                 if is_reverse:
 *                     reads_pp_rev_nodel += 1             # <<<<<<<<<<<<<<
 *                     baseq_pp_rev_squared_sum += baseq_squared
 *                 else:
 */
          __pyx_v_reads_pp_rev_nodel = (__pyx_v_reads_pp_rev_nodel + 1);

          /* "pysamstats.pyx":1549
 *                 if is_reverse:
 *                     reads_pp_rev_nodel += 1
 *                     baseq_pp_rev_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                 else:
 *                     reads_pp_fwd_nodel += 1
 */
          __pyx_v_baseq_pp_rev_squared_sum = (__pyx_v_baseq_pp_rev_squared_sum + __pyx_v_baseq_squared);
          goto __pyx_L8;
        }
        /*else*/ {

          /* "pysamstats.pyx":1551
 *                     baseq_pp_rev_squared_sum += baseq_squared
 *                 else:
 *                     reads_pp_fwd_nodel += 1             # <<<<<<<<<<<<<<
 *                     baseq_pp_fwd_squared_sum += baseq_squared
 * 
 */
          __pyx_v_reads_pp_fwd_nodel = (__pyx_v_reads_pp_fwd_nodel + 1);

          /* "pysamstats.pyx":1552
 *                 else:
 *                     reads_pp_fwd_nodel += 1
 *                     baseq_pp_fwd_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 * 
 *     # construct output variables
 */
          __pyx_v_baseq_pp_fwd_squared_sum = (__pyx_v_baseq_pp_fwd_squared_sum + __pyx_v_baseq_squared);
        }
        __pyx_L8:;
        goto __pyx_L7;
      }
      __pyx_L7:;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  /* "pysamstats.pyx":1555
 * 
 *     # construct output variables
 *     rms_baseq = rootmean(baseq_squared_sum, reads_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_rev = rootmean(baseq_rev_squared_sum, reads_rev_nodel)
 *     rms_baseq_fwd = rootmean(baseq_fwd_squared_sum, reads_fwd_nodel)
 */
  __pyx_t_4 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_squared_sum, __pyx_v_reads_nodel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1555; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_rms_baseq = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1556
 *     # construct output variables
 *     rms_baseq = rootmean(baseq_squared_sum, reads_nodel)
 *     rms_baseq_rev = rootmean(baseq_rev_squared_sum, reads_rev_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_fwd = rootmean(baseq_fwd_squared_sum, reads_fwd_nodel)
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 */
  __pyx_t_4 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_rev_squared_sum, __pyx_v_reads_rev_nodel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_rms_baseq_rev = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1557
 *     rms_baseq = rootmean(baseq_squared_sum, reads_nodel)
 *     rms_baseq_rev = rootmean(baseq_rev_squared_sum, reads_rev_nodel)
 *     rms_baseq_fwd = rootmean(baseq_fwd_squared_sum, reads_fwd_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 *     rms_baseq_pp_fwd = rootmean(baseq_pp_fwd_squared_sum, reads_pp_fwd_nodel)
 */
  __pyx_t_4 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_fwd_squared_sum, __pyx_v_reads_fwd_nodel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1557; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_rms_baseq_fwd = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1558
 *     rms_baseq_rev = rootmean(baseq_rev_squared_sum, reads_rev_nodel)
 *     rms_baseq_fwd = rootmean(baseq_fwd_squared_sum, reads_fwd_nodel)
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_pp_fwd = rootmean(baseq_pp_fwd_squared_sum, reads_pp_fwd_nodel)
 *     rms_baseq_pp_rev = rootmean(baseq_pp_rev_squared_sum, reads_pp_rev_nodel)
 */
  __pyx_t_4 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_pp_squared_sum, __pyx_v_reads_pp_nodel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1558; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_rms_baseq_pp = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1559
 *     rms_baseq_fwd = rootmean(baseq_fwd_squared_sum, reads_fwd_nodel)
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 *     rms_baseq_pp_fwd = rootmean(baseq_pp_fwd_squared_sum, reads_pp_fwd_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_pp_rev = rootmean(baseq_pp_rev_squared_sum, reads_pp_rev_nodel)
 * 
 */
  __pyx_t_4 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_pp_fwd_squared_sum, __pyx_v_reads_pp_fwd_nodel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1559; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_rms_baseq_pp_fwd = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1560
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 *     rms_baseq_pp_fwd = rootmean(baseq_pp_fwd_squared_sum, reads_pp_fwd_nodel)
 *     rms_baseq_pp_rev = rootmean(baseq_pp_rev_squared_sum, reads_pp_rev_nodel)             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom,
 */
  __pyx_t_4 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_pp_rev_squared_sum, __pyx_v_reads_pp_rev_nodel); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1560; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_rms_baseq_pp_rev = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1562
 *     rms_baseq_pp_rev = rootmean(baseq_pp_rev_squared_sum, reads_pp_rev_nodel)
 * 
 *     return {'chrom': chrom,             # <<<<<<<<<<<<<<
 *             'pos': pos,
 * #            'reads_all': n,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1563
 * 
 *     return {'chrom': chrom,
 *             'pos': pos,             # <<<<<<<<<<<<<<
 * #            'reads_all': n,
 * #            'reads_fwd': reads_fwd,
 */
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1563; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "pysamstats.pyx":1570
 * #            'reads_pp_fwd': reads_pp_fwd,
 * #            'reads_pp_rev': reads_pp_rev,
 *             'rms_baseq': rms_baseq,             # <<<<<<<<<<<<<<
 *             'rms_baseq_fwd': rms_baseq_fwd,
 *             'rms_baseq_rev': rms_baseq_rev,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_baseq), __pyx_v_rms_baseq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1571
 * #            'reads_pp_rev': reads_pp_rev,
 *             'rms_baseq': rms_baseq,
 *             'rms_baseq_fwd': rms_baseq_fwd,             # <<<<<<<<<<<<<<
 *             'rms_baseq_rev': rms_baseq_rev,
 *             'rms_baseq_pp': rms_baseq_pp,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_baseq_fwd), __pyx_v_rms_baseq_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1572
 *             'rms_baseq': rms_baseq,
 *             'rms_baseq_fwd': rms_baseq_fwd,
 *             'rms_baseq_rev': rms_baseq_rev,             # <<<<<<<<<<<<<<
 *             'rms_baseq_pp': rms_baseq_pp,
 *             'rms_baseq_pp_fwd': rms_baseq_pp_fwd,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_baseq_rev), __pyx_v_rms_baseq_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1573
 *             'rms_baseq_fwd': rms_baseq_fwd,
 *             'rms_baseq_rev': rms_baseq_rev,
 *             'rms_baseq_pp': rms_baseq_pp,             # <<<<<<<<<<<<<<
 *             'rms_baseq_pp_fwd': rms_baseq_pp_fwd,
 *             'rms_baseq_pp_rev': rms_baseq_pp_rev,
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_baseq_pp), __pyx_v_rms_baseq_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1574
 *             'rms_baseq_rev': rms_baseq_rev,
 *             'rms_baseq_pp': rms_baseq_pp,
 *             'rms_baseq_pp_fwd': rms_baseq_pp_fwd,             # <<<<<<<<<<<<<<
 *             'rms_baseq_pp_rev': rms_baseq_pp_rev,
 *             }
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_baseq_pp_fwd), __pyx_v_rms_baseq_pp_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1575
 *             'rms_baseq_pp': rms_baseq_pp,
 *             'rms_baseq_pp_fwd': rms_baseq_pp_fwd,
 *             'rms_baseq_pp_rev': rms_baseq_pp_rev,             # <<<<<<<<<<<<<<
 *             }
 * 
 */
  if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__rms_baseq_pp_rev), __pyx_v_rms_baseq_pp_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1562; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_rms_baseq);
  __Pyx_XDECREF(__pyx_v_rms_baseq_rev);
  __Pyx_XDECREF(__pyx_v_rms_baseq_fwd);
  __Pyx_XDECREF(__pyx_v_rms_baseq_pp);
  __Pyx_XDECREF(__pyx_v_rms_baseq_pp_fwd);
  __Pyx_XDECREF(__pyx_v_rms_baseq_pp_rev);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_78construct_rec_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_78construct_rec_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_baseq_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__col,&__pyx_n_s__one_based,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__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_baseq_strand", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_baseq_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[1]);
    if (values[2]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1471
 * 
 * 
 * cpdef object construct_rec_baseq_strand(Samfile samfile, PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_baseq_strand", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_77construct_rec_baseq_strand(__pyx_self, __pyx_v_samfile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_77construct_rec_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_baseq_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_baseq_strand", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_baseq_strand(__pyx_v_samfile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_81generator11(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_80stat_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_80stat_baseq_strand = {__Pyx_NAMESTR("stat_baseq_strand"), (PyCFunction)__pyx_pw_10pysamstats_80stat_baseq_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_80stat_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_baseq_strand (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__samfile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysamstats.pyx":1579
 * 
 * 
 * def stat_baseq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_36;
    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__chrom);
          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__one_based);
          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, "stat_baseq_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
    __pyx_v_one_based = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_baseq_strand", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_baseq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_79stat_baseq_strand(__pyx_self, __pyx_v_samfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_10pysamstats_79stat_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_baseq_strand", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *)__pyx_ptype_10pysamstats___pyx_scope_struct_11_stat_baseq_strand->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_11_stat_baseq_strand, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_81generator11, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_baseq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_81generator11(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_baseq_strand __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1580
 * 
 * def stat_baseq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_baseq_strand(samfile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 1580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1580; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1581
 * def stat_baseq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_baseq_strand(samfile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 1581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1581; __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 = 1581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1581; __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 = 1581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":1582
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_baseq_strand(samfile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_baseq_strand(__pyx_cur_scope->__pyx_v_samfile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_baseq_strand", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_83write_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_83write_baseq_strand = {__Pyx_NAMESTR("write_baseq_strand"), (PyCFunction)__pyx_pw_10pysamstats_83write_baseq_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_83write_baseq_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_baseq_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_baseq_strand", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_82write_baseq_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1585
 * 
 * 
 * def write_baseq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 */

static PyObject *__pyx_pf_10pysamstats_82write_baseq_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_baseq_strand", 0);

  /* "pysamstats.pyx":1586
 * 
 * def write_baseq_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 * #                  'reads_pp', 'reads_pp_fwd', 'reads_pp_rev',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_37));
  __pyx_v_fieldnames = __pyx_k_tuple_37;

  /* "pysamstats.pyx":1592
 *                   'rms_baseq_pp', 'rms_baseq_pp_fwd', 'rms_baseq_pp_rev',
 *                   )
 *     write_stats(stat_baseq_strand, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_baseq_strand); 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_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1592; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_baseq_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1600
 * 
 * 
 * cpdef object construct_rec_baseq_ext(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                      PileupProxy col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_85construct_rec_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_baseq_ext(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext *__pyx_optional_args) {

  /* "pysamstats.pyx":1601
 * 
 * cpdef object construct_rec_baseq_ext(Samfile samfile, Fastafile fafile,
 *                                      PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  unsigned int __pyx_v_reads_nodel;
  unsigned int __pyx_v_reads_pp_nodel;
  unsigned int __pyx_v_matches;
  unsigned int __pyx_v_matches_pp;
  unsigned int __pyx_v_mismatches;
  unsigned int __pyx_v_mismatches_pp;
  uint64_t __pyx_v_baseq;
  uint64_t __pyx_v_baseq_squared;
  uint64_t __pyx_v_baseq_squared_sum;
  uint64_t __pyx_v_baseq_pp_squared_sum;
  uint64_t __pyx_v_baseq_matches_squared_sum;
  uint64_t __pyx_v_baseq_matches_pp_squared_sum;
  uint64_t __pyx_v_baseq_mismatches_squared_sum;
  uint64_t __pyx_v_baseq_mismatches_pp_squared_sum;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_v_refbase = NULL;
  PyObject *__pyx_v_alnbase = NULL;
  PyObject *__pyx_v_rms_baseq = NULL;
  PyObject *__pyx_v_rms_baseq_pp = NULL;
  PyObject *__pyx_v_rms_baseq_matches = NULL;
  PyObject *__pyx_v_rms_baseq_matches_pp = NULL;
  PyObject *__pyx_v_rms_baseq_mismatches = NULL;
  PyObject *__pyx_v_rms_baseq_mismatches_pp = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_baseq_ext", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":1612
 *     cdef bint is_proper_pair
 *     # counting variables
 *     cdef unsigned int reads_nodel = 0             # <<<<<<<<<<<<<<
 * #    cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_nodel = 0
 */
  __pyx_v_reads_nodel = 0;

  /* "pysamstats.pyx":1614
 *     cdef unsigned int reads_nodel = 0
 * #    cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int matches = 0
 *     cdef unsigned int matches_pp = 0
 */
  __pyx_v_reads_pp_nodel = 0;

  /* "pysamstats.pyx":1615
 * #    cdef unsigned int reads_pp = 0
 *     cdef unsigned int reads_pp_nodel = 0
 *     cdef unsigned int matches = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int matches_pp = 0
 *     cdef unsigned int mismatches = 0
 */
  __pyx_v_matches = 0;

  /* "pysamstats.pyx":1616
 *     cdef unsigned int reads_pp_nodel = 0
 *     cdef unsigned int matches = 0
 *     cdef unsigned int matches_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int mismatches = 0
 *     cdef unsigned int mismatches_pp = 0
 */
  __pyx_v_matches_pp = 0;

  /* "pysamstats.pyx":1617
 *     cdef unsigned int matches = 0
 *     cdef unsigned int matches_pp = 0
 *     cdef unsigned int mismatches = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int mismatches_pp = 0
 * 
 */
  __pyx_v_mismatches = 0;

  /* "pysamstats.pyx":1618
 *     cdef unsigned int matches_pp = 0
 *     cdef unsigned int mismatches = 0
 *     cdef unsigned int mismatches_pp = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef uint64_t baseq
 */
  __pyx_v_mismatches_pp = 0;

  /* "pysamstats.pyx":1623
 *     cdef uint64_t baseq_squared
 * 
 *     cdef uint64_t baseq_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_pp_squared_sum = 0
 *     cdef uint64_t baseq_matches_squared_sum = 0
 */
  __pyx_v_baseq_squared_sum = 0;

  /* "pysamstats.pyx":1624
 * 
 *     cdef uint64_t baseq_squared_sum = 0
 *     cdef uint64_t baseq_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_matches_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_squared_sum = 0
 */
  __pyx_v_baseq_pp_squared_sum = 0;

  /* "pysamstats.pyx":1625
 *     cdef uint64_t baseq_squared_sum = 0
 *     cdef uint64_t baseq_pp_squared_sum = 0
 *     cdef uint64_t baseq_matches_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_matches_pp_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_squared_sum = 0
 */
  __pyx_v_baseq_matches_squared_sum = 0;

  /* "pysamstats.pyx":1626
 *     cdef uint64_t baseq_pp_squared_sum = 0
 *     cdef uint64_t baseq_matches_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_mismatches_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_pp_squared_sum = 0
 */
  __pyx_v_baseq_matches_pp_squared_sum = 0;

  /* "pysamstats.pyx":1627
 *     cdef uint64_t baseq_matches_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_mismatches_pp_squared_sum = 0
 * 
 */
  __pyx_v_baseq_mismatches_squared_sum = 0;

  /* "pysamstats.pyx":1628
 *     cdef uint64_t baseq_matches_pp_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_baseq_mismatches_pp_squared_sum = 0;

  /* "pysamstats.pyx":1631
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":1632
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":1635
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1636
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # reference base
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":1639
 * 
 *     # reference base
 *     refbase = fafile.fetch(reference=chrom, start=col.pos, end=col.pos+1).upper()             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_fafile), __pyx_n_s__fetch); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__reference), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = PyInt_FromLong(__pyx_v_col->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__start), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyInt_FromLong((__pyx_v_col->pos + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__end), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__upper); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1642
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":1643
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":1644
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":1645
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 * #        if is_proper_pair:
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":1646
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 * #        if is_proper_pair:
 * #            reads_pp += 1
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":1649
 * #        if is_proper_pair:
 * #            reads_pp += 1
 *         if not read.is_del:             # <<<<<<<<<<<<<<
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]
 */
    __pyx_t_10 = (!__pyx_v_read->is_del);
    if (__pyx_t_10) {

      /* "pysamstats.pyx":1650
 * #            reads_pp += 1
 *         if not read.is_del:
 *             reads_nodel += 1             # <<<<<<<<<<<<<<
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 */
      __pyx_v_reads_nodel = (__pyx_v_reads_nodel + 1);

      /* "pysamstats.pyx":1651
 *         if not read.is_del:
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]             # <<<<<<<<<<<<<<
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 */
      __pyx_v_baseq = (bam1_qual(__pyx_v_aln)[__pyx_v_read->qpos]);

      /* "pysamstats.pyx":1652
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2             # <<<<<<<<<<<<<<
 *             baseq_squared_sum += baseq_squared
 *             if is_proper_pair:
 */
      __pyx_v_baseq_squared = __Pyx_pow_uint64_t(__pyx_v_baseq, 2);

      /* "pysamstats.pyx":1653
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1
 */
      __pyx_v_baseq_squared_sum = (__pyx_v_baseq_squared_sum + __pyx_v_baseq_squared);

      /* "pysamstats.pyx":1654
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared
 */
      if (__pyx_v_is_proper_pair) {

        /* "pysamstats.pyx":1655
 *             baseq_squared_sum += baseq_squared
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1             # <<<<<<<<<<<<<<
 *                 baseq_pp_squared_sum += baseq_squared
 *             alnbase = get_seq_base(aln, read.qpos)
 */
        __pyx_v_reads_pp_nodel = (__pyx_v_reads_pp_nodel + 1);

        /* "pysamstats.pyx":1656
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             alnbase = get_seq_base(aln, read.qpos)
 *             if alnbase == refbase:
 */
        __pyx_v_baseq_pp_squared_sum = (__pyx_v_baseq_pp_squared_sum + __pyx_v_baseq_squared);
        goto __pyx_L6;
      }
      __pyx_L6:;

      /* "pysamstats.pyx":1657
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared
 *             alnbase = get_seq_base(aln, read.qpos)             # <<<<<<<<<<<<<<
 *             if alnbase == refbase:
 *                 matches += 1
 */
      __pyx_t_1 = __pyx_f_10pysamstats_get_seq_base(__pyx_v_aln, __pyx_v_read->qpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1657; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_v_alnbase);
      __pyx_v_alnbase = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "pysamstats.pyx":1658
 *                 baseq_pp_squared_sum += baseq_squared
 *             alnbase = get_seq_base(aln, read.qpos)
 *             if alnbase == refbase:             # <<<<<<<<<<<<<<
 *                 matches += 1
 *                 baseq_matches_squared_sum += baseq_squared
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, __pyx_v_refbase, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1658; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1658; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":1659
 *             alnbase = get_seq_base(aln, read.qpos)
 *             if alnbase == refbase:
 *                 matches += 1             # <<<<<<<<<<<<<<
 *                 baseq_matches_squared_sum += baseq_squared
 *                 if is_proper_pair:
 */
        __pyx_v_matches = (__pyx_v_matches + 1);

        /* "pysamstats.pyx":1660
 *             if alnbase == refbase:
 *                 matches += 1
 *                 baseq_matches_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     matches_pp += 1
 */
        __pyx_v_baseq_matches_squared_sum = (__pyx_v_baseq_matches_squared_sum + __pyx_v_baseq_squared);

        /* "pysamstats.pyx":1661
 *                 matches += 1
 *                 baseq_matches_squared_sum += baseq_squared
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     matches_pp += 1
 *                     baseq_matches_pp_squared_sum += baseq_squared
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":1662
 *                 baseq_matches_squared_sum += baseq_squared
 *                 if is_proper_pair:
 *                     matches_pp += 1             # <<<<<<<<<<<<<<
 *                     baseq_matches_pp_squared_sum += baseq_squared
 *             else:
 */
          __pyx_v_matches_pp = (__pyx_v_matches_pp + 1);

          /* "pysamstats.pyx":1663
 *                 if is_proper_pair:
 *                     matches_pp += 1
 *                     baseq_matches_pp_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             else:
 *                 mismatches += 1
 */
          __pyx_v_baseq_matches_pp_squared_sum = (__pyx_v_baseq_matches_pp_squared_sum + __pyx_v_baseq_squared);
          goto __pyx_L8;
        }
        __pyx_L8:;
        goto __pyx_L7;
      }
      /*else*/ {

        /* "pysamstats.pyx":1665
 *                     baseq_matches_pp_squared_sum += baseq_squared
 *             else:
 *                 mismatches += 1             # <<<<<<<<<<<<<<
 *                 baseq_mismatches_squared_sum += baseq_squared
 *                 if is_proper_pair:
 */
        __pyx_v_mismatches = (__pyx_v_mismatches + 1);

        /* "pysamstats.pyx":1666
 *             else:
 *                 mismatches += 1
 *                 baseq_mismatches_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                 if is_proper_pair:
 *                     mismatches_pp += 1
 */
        __pyx_v_baseq_mismatches_squared_sum = (__pyx_v_baseq_mismatches_squared_sum + __pyx_v_baseq_squared);

        /* "pysamstats.pyx":1667
 *                 mismatches += 1
 *                 baseq_mismatches_squared_sum += baseq_squared
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     mismatches_pp += 1
 *                     baseq_mismatches_pp_squared_sum += baseq_squared
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":1668
 *                 baseq_mismatches_squared_sum += baseq_squared
 *                 if is_proper_pair:
 *                     mismatches_pp += 1             # <<<<<<<<<<<<<<
 *                     baseq_mismatches_pp_squared_sum += baseq_squared
 * 
 */
          __pyx_v_mismatches_pp = (__pyx_v_mismatches_pp + 1);

          /* "pysamstats.pyx":1669
 *                 if is_proper_pair:
 *                     mismatches_pp += 1
 *                     baseq_mismatches_pp_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 * 
 *     # construct output variables
 */
          __pyx_v_baseq_mismatches_pp_squared_sum = (__pyx_v_baseq_mismatches_pp_squared_sum + __pyx_v_baseq_squared);
          goto __pyx_L9;
        }
        __pyx_L9:;
      }
      __pyx_L7:;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  /* "pysamstats.pyx":1672
 * 
 *     # construct output variables
 *     rms_baseq = rootmean(baseq_squared_sum, reads_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 *     rms_baseq_matches = rootmean(baseq_matches_squared_sum, matches)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_squared_sum, __pyx_v_reads_nodel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1672; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1673
 *     # construct output variables
 *     rms_baseq = rootmean(baseq_squared_sum, reads_nodel)
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_matches = rootmean(baseq_matches_squared_sum, matches)
 *     rms_baseq_matches_pp = rootmean(baseq_matches_pp_squared_sum, matches_pp)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_pp_squared_sum, __pyx_v_reads_pp_nodel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_pp = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1674
 *     rms_baseq = rootmean(baseq_squared_sum, reads_nodel)
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 *     rms_baseq_matches = rootmean(baseq_matches_squared_sum, matches)             # <<<<<<<<<<<<<<
 *     rms_baseq_matches_pp = rootmean(baseq_matches_pp_squared_sum, matches_pp)
 *     rms_baseq_mismatches = rootmean(baseq_mismatches_squared_sum, mismatches)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_matches_squared_sum, __pyx_v_matches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1674; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_matches = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1675
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 *     rms_baseq_matches = rootmean(baseq_matches_squared_sum, matches)
 *     rms_baseq_matches_pp = rootmean(baseq_matches_pp_squared_sum, matches_pp)             # <<<<<<<<<<<<<<
 *     rms_baseq_mismatches = rootmean(baseq_mismatches_squared_sum, mismatches)
 *     rms_baseq_mismatches_pp = rootmean(baseq_mismatches_pp_squared_sum, mismatches_pp)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_matches_pp_squared_sum, __pyx_v_matches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1675; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_matches_pp = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1676
 *     rms_baseq_matches = rootmean(baseq_matches_squared_sum, matches)
 *     rms_baseq_matches_pp = rootmean(baseq_matches_pp_squared_sum, matches_pp)
 *     rms_baseq_mismatches = rootmean(baseq_mismatches_squared_sum, mismatches)             # <<<<<<<<<<<<<<
 *     rms_baseq_mismatches_pp = rootmean(baseq_mismatches_pp_squared_sum, mismatches_pp)
 * 
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_mismatches_squared_sum, __pyx_v_mismatches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1676; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_mismatches = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1677
 *     rms_baseq_matches_pp = rootmean(baseq_matches_pp_squared_sum, matches_pp)
 *     rms_baseq_mismatches = rootmean(baseq_mismatches_squared_sum, mismatches)
 *     rms_baseq_mismatches_pp = rootmean(baseq_mismatches_pp_squared_sum, mismatches_pp)             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_mismatches_pp_squared_sum, __pyx_v_mismatches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1677; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_mismatches_pp = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1679
 *     rms_baseq_mismatches_pp = rootmean(baseq_mismatches_pp_squared_sum, mismatches_pp)
 * 
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,             # <<<<<<<<<<<<<<
 * #            'reads_all': n, 'reads_pp': reads_pp,
 * #            'matches': matches,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__ref), __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1685
 * #            'mismatches': mismatches,
 * #            'mismatches_pp': mismatches_pp,
 *             'rms_baseq': rms_baseq,             # <<<<<<<<<<<<<<
 *             'rms_baseq_pp': rms_baseq_pp,
 *             'rms_baseq_matches': rms_baseq_matches,
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__rms_baseq), __pyx_v_rms_baseq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1686
 * #            'mismatches_pp': mismatches_pp,
 *             'rms_baseq': rms_baseq,
 *             'rms_baseq_pp': rms_baseq_pp,             # <<<<<<<<<<<<<<
 *             'rms_baseq_matches': rms_baseq_matches,
 *             'rms_baseq_matches_pp': rms_baseq_matches_pp,
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__rms_baseq_pp), __pyx_v_rms_baseq_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1687
 *             'rms_baseq': rms_baseq,
 *             'rms_baseq_pp': rms_baseq_pp,
 *             'rms_baseq_matches': rms_baseq_matches,             # <<<<<<<<<<<<<<
 *             'rms_baseq_matches_pp': rms_baseq_matches_pp,
 *             'rms_baseq_mismatches': rms_baseq_mismatches,
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__rms_baseq_matches), __pyx_v_rms_baseq_matches) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1688
 *             'rms_baseq_pp': rms_baseq_pp,
 *             'rms_baseq_matches': rms_baseq_matches,
 *             'rms_baseq_matches_pp': rms_baseq_matches_pp,             # <<<<<<<<<<<<<<
 *             'rms_baseq_mismatches': rms_baseq_mismatches,
 *             'rms_baseq_mismatches_pp': rms_baseq_mismatches_pp,
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_38), __pyx_v_rms_baseq_matches_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1689
 *             'rms_baseq_matches': rms_baseq_matches,
 *             'rms_baseq_matches_pp': rms_baseq_matches_pp,
 *             'rms_baseq_mismatches': rms_baseq_mismatches,             # <<<<<<<<<<<<<<
 *             'rms_baseq_mismatches_pp': rms_baseq_mismatches_pp,
 *             }
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_39), __pyx_v_rms_baseq_mismatches) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1690
 *             'rms_baseq_matches_pp': rms_baseq_matches_pp,
 *             'rms_baseq_mismatches': rms_baseq_mismatches,
 *             'rms_baseq_mismatches_pp': rms_baseq_mismatches_pp,             # <<<<<<<<<<<<<<
 *             }
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_40), __pyx_v_rms_baseq_mismatches_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1679; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_refbase);
  __Pyx_XDECREF(__pyx_v_alnbase);
  __Pyx_XDECREF(__pyx_v_rms_baseq);
  __Pyx_XDECREF(__pyx_v_rms_baseq_pp);
  __Pyx_XDECREF(__pyx_v_rms_baseq_matches);
  __Pyx_XDECREF(__pyx_v_rms_baseq_matches_pp);
  __Pyx_XDECREF(__pyx_v_rms_baseq_mismatches);
  __Pyx_XDECREF(__pyx_v_rms_baseq_mismatches_pp);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_85construct_rec_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_85construct_rec_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_baseq_ext (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__fafile,&__pyx_n_s__col,&__pyx_n_s__one_based,0};
    PyObject* values[4] = {0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_baseq_ext", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_baseq_ext", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_baseq_ext") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __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);
        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_9csamtools_Samfile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[2]);
    if (values[3]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1601
 * 
 * cpdef object construct_rec_baseq_ext(Samfile samfile, Fastafile fafile,
 *                                      PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_baseq_ext", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_84construct_rec_baseq_ext(__pyx_self, __pyx_v_samfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1600
 * 
 * 
 * cpdef object construct_rec_baseq_ext(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                      PileupProxy col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pf_10pysamstats_84construct_rec_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_baseq_ext", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_baseq_ext(__pyx_v_samfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1600; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_88generator12(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_87stat_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_87stat_baseq_ext = {__Pyx_NAMESTR("stat_baseq_ext"), (PyCFunction)__pyx_pw_10pysamstats_87stat_baseq_ext, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_87stat_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_baseq_ext (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__samfile,&__pyx_n_s__fafile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "pysamstats.pyx":1695
 * 
 * def stat_baseq_ext(Samfile samfile, Fastafile fafile,
 *                    chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    values[5] = __pyx_k_41;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        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__fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stat_baseq_ext", 0, 2, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__chrom);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_baseq_ext") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)values[1]);
    __pyx_v_chrom = values[2];
    __pyx_v_start = values[3];
    __pyx_v_end = values[4];
    __pyx_v_one_based = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_baseq_ext", 0, 2, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_baseq_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_86stat_baseq_ext(__pyx_self, __pyx_v_samfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1694
 * 
 * 
 * def stat_baseq_ext(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                    chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */

static PyObject *__pyx_pf_10pysamstats_86stat_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_baseq_ext", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *)__pyx_ptype_10pysamstats___pyx_scope_struct_12_stat_baseq_ext->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_12_stat_baseq_ext, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_fafile = __pyx_v_fafile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_88generator12, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_baseq_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_88generator12(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1696
 * def stat_baseq_ext(Samfile samfile, Fastafile fafile,
 *                    chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_baseq_ext(samfile, fafile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1696; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1697
 *                    chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_baseq_ext(samfile, fafile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1697; __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 = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1697; __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 = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":1698
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_baseq_ext(samfile, fafile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_baseq_ext(__pyx_cur_scope->__pyx_v_samfile, __pyx_cur_scope->__pyx_v_fafile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_baseq_ext", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_90write_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_90write_baseq_ext = {__Pyx_NAMESTR("write_baseq_ext"), (PyCFunction)__pyx_pw_10pysamstats_90write_baseq_ext, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_90write_baseq_ext(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_baseq_ext (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_baseq_ext", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_89write_baseq_ext(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1701
 * 
 * 
 * def write_baseq_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 * #                  'reads_all', 'reads_pp',
 */

static PyObject *__pyx_pf_10pysamstats_89write_baseq_ext(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_baseq_ext", 0);

  /* "pysamstats.pyx":1702
 * 
 * def write_baseq_ext(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'ref',             # <<<<<<<<<<<<<<
 * #                  'reads_all', 'reads_pp',
 * #                  'matches', 'matches_pp',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_42));
  __pyx_v_fieldnames = __pyx_k_tuple_42;

  /* "pysamstats.pyx":1710
 *                   'rms_baseq_mismatches', 'rms_baseq_mismatches_pp',
 *                   )
 *     write_stats(stat_baseq_ext, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_baseq_ext); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __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 = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1710; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_baseq_ext", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1718
 * 
 * 
 * cpdef object construct_rec_baseq_ext_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                             PileupProxy col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pw_10pysamstats_92construct_rec_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_10pysamstats_construct_rec_baseq_ext_strand(struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext_strand *__pyx_optional_args) {

  /* "pysamstats.pyx":1719
 * 
 * cpdef object construct_rec_baseq_ext_strand(Samfile samfile, Fastafile fafile,
 *                                             PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
  int __pyx_v_one_based = ((int)0);
  bam_pileup1_t **__pyx_v_plp;
  bam_pileup1_t *__pyx_v_read;
  bam1_t *__pyx_v_aln;
  int __pyx_v_i;
  int __pyx_v_n;
  uint32_t __pyx_v_flag;
  int __pyx_v_is_proper_pair;
  int __pyx_v_is_reverse;
  unsigned int __pyx_v_reads_nodel;
  unsigned int __pyx_v_reads_fwd_nodel;
  unsigned int __pyx_v_reads_rev_nodel;
  unsigned int __pyx_v_reads_pp_nodel;
  unsigned int __pyx_v_reads_pp_fwd_nodel;
  unsigned int __pyx_v_reads_pp_rev_nodel;
  unsigned int __pyx_v_matches;
  unsigned int __pyx_v_matches_fwd;
  unsigned int __pyx_v_matches_rev;
  unsigned int __pyx_v_matches_pp;
  unsigned int __pyx_v_matches_pp_fwd;
  unsigned int __pyx_v_matches_pp_rev;
  unsigned int __pyx_v_mismatches;
  unsigned int __pyx_v_mismatches_fwd;
  unsigned int __pyx_v_mismatches_rev;
  unsigned int __pyx_v_mismatches_pp;
  unsigned int __pyx_v_mismatches_pp_fwd;
  unsigned int __pyx_v_mismatches_pp_rev;
  uint64_t __pyx_v_baseq;
  uint64_t __pyx_v_baseq_squared;
  uint64_t __pyx_v_baseq_squared_sum;
  uint64_t __pyx_v_baseq_fwd_squared_sum;
  uint64_t __pyx_v_baseq_rev_squared_sum;
  uint64_t __pyx_v_baseq_pp_squared_sum;
  uint64_t __pyx_v_baseq_pp_fwd_squared_sum;
  uint64_t __pyx_v_baseq_pp_rev_squared_sum;
  uint64_t __pyx_v_baseq_matches_squared_sum;
  uint64_t __pyx_v_baseq_matches_fwd_squared_sum;
  uint64_t __pyx_v_baseq_matches_rev_squared_sum;
  uint64_t __pyx_v_baseq_matches_pp_squared_sum;
  uint64_t __pyx_v_baseq_matches_pp_fwd_squared_sum;
  uint64_t __pyx_v_baseq_matches_pp_rev_squared_sum;
  uint64_t __pyx_v_baseq_mismatches_squared_sum;
  uint64_t __pyx_v_baseq_mismatches_fwd_squared_sum;
  uint64_t __pyx_v_baseq_mismatches_rev_squared_sum;
  uint64_t __pyx_v_baseq_mismatches_pp_squared_sum;
  uint64_t __pyx_v_baseq_mismatches_pp_fwd_squared_sum;
  uint64_t __pyx_v_baseq_mismatches_pp_rev_squared_sum;
  PyObject *__pyx_v_chrom = NULL;
  long __pyx_v_pos;
  PyObject *__pyx_v_refbase = NULL;
  PyObject *__pyx_v_alnbase = NULL;
  PyObject *__pyx_v_rms_baseq = NULL;
  PyObject *__pyx_v_rms_baseq_fwd = NULL;
  PyObject *__pyx_v_rms_baseq_rev = NULL;
  PyObject *__pyx_v_rms_baseq_pp = NULL;
  PyObject *__pyx_v_rms_baseq_pp_fwd = NULL;
  PyObject *__pyx_v_rms_baseq_pp_rev = NULL;
  PyObject *__pyx_v_rms_baseq_matches = NULL;
  PyObject *__pyx_v_rms_baseq_matches_fwd = NULL;
  PyObject *__pyx_v_rms_baseq_matches_rev = NULL;
  PyObject *__pyx_v_rms_baseq_matches_pp = NULL;
  PyObject *__pyx_v_rms_baseq_matches_pp_fwd = NULL;
  PyObject *__pyx_v_rms_baseq_matches_pp_rev = NULL;
  PyObject *__pyx_v_rms_baseq_mismatches = NULL;
  PyObject *__pyx_v_rms_baseq_mismatches_fwd = NULL;
  PyObject *__pyx_v_rms_baseq_mismatches_rev = NULL;
  PyObject *__pyx_v_rms_baseq_mismatches_pp = NULL;
  PyObject *__pyx_v_rms_baseq_mismatches_pp_fwd = NULL;
  PyObject *__pyx_v_rms_baseq_mismatches_pp_rev = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  bam_pileup1_t **__pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  long __pyx_t_6;
  int __pyx_t_7;
  bam1_t *__pyx_t_8;
  uint32_t __pyx_t_9;
  int __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_baseq_ext_strand", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_one_based = __pyx_optional_args->one_based;
    }
  }

  /* "pysamstats.pyx":1734
 * #    cdef unsigned int reads_fwd = 0
 * #    cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_fwd_nodel = 0
 *     cdef unsigned int reads_rev_nodel = 0
 */
  __pyx_v_reads_nodel = 0;

  /* "pysamstats.pyx":1735
 * #    cdef unsigned int reads_rev = 0
 *     cdef unsigned int reads_nodel = 0
 *     cdef unsigned int reads_fwd_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_rev_nodel = 0
 * #    cdef unsigned int reads_pp = 0
 */
  __pyx_v_reads_fwd_nodel = 0;

  /* "pysamstats.pyx":1736
 *     cdef unsigned int reads_nodel = 0
 *     cdef unsigned int reads_fwd_nodel = 0
 *     cdef unsigned int reads_rev_nodel = 0             # <<<<<<<<<<<<<<
 * #    cdef unsigned int reads_pp = 0
 * #    cdef unsigned int reads_pp_fwd = 0
 */
  __pyx_v_reads_rev_nodel = 0;

  /* "pysamstats.pyx":1740
 * #    cdef unsigned int reads_pp_fwd = 0
 * #    cdef unsigned int reads_pp_rev = 0
 *     cdef unsigned int reads_pp_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_fwd_nodel = 0
 *     cdef unsigned int reads_pp_rev_nodel = 0
 */
  __pyx_v_reads_pp_nodel = 0;

  /* "pysamstats.pyx":1741
 * #    cdef unsigned int reads_pp_rev = 0
 *     cdef unsigned int reads_pp_nodel = 0
 *     cdef unsigned int reads_pp_fwd_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int reads_pp_rev_nodel = 0
 *     cdef unsigned int matches = 0
 */
  __pyx_v_reads_pp_fwd_nodel = 0;

  /* "pysamstats.pyx":1742
 *     cdef unsigned int reads_pp_nodel = 0
 *     cdef unsigned int reads_pp_fwd_nodel = 0
 *     cdef unsigned int reads_pp_rev_nodel = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int matches = 0
 *     cdef unsigned int matches_fwd = 0
 */
  __pyx_v_reads_pp_rev_nodel = 0;

  /* "pysamstats.pyx":1743
 *     cdef unsigned int reads_pp_fwd_nodel = 0
 *     cdef unsigned int reads_pp_rev_nodel = 0
 *     cdef unsigned int matches = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int matches_fwd = 0
 *     cdef unsigned int matches_rev = 0
 */
  __pyx_v_matches = 0;

  /* "pysamstats.pyx":1744
 *     cdef unsigned int reads_pp_rev_nodel = 0
 *     cdef unsigned int matches = 0
 *     cdef unsigned int matches_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int matches_rev = 0
 *     cdef unsigned int matches_pp = 0
 */
  __pyx_v_matches_fwd = 0;

  /* "pysamstats.pyx":1745
 *     cdef unsigned int matches = 0
 *     cdef unsigned int matches_fwd = 0
 *     cdef unsigned int matches_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int matches_pp = 0
 *     cdef unsigned int matches_pp_fwd = 0
 */
  __pyx_v_matches_rev = 0;

  /* "pysamstats.pyx":1746
 *     cdef unsigned int matches_fwd = 0
 *     cdef unsigned int matches_rev = 0
 *     cdef unsigned int matches_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int matches_pp_fwd = 0
 *     cdef unsigned int matches_pp_rev = 0
 */
  __pyx_v_matches_pp = 0;

  /* "pysamstats.pyx":1747
 *     cdef unsigned int matches_rev = 0
 *     cdef unsigned int matches_pp = 0
 *     cdef unsigned int matches_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int matches_pp_rev = 0
 *     cdef unsigned int mismatches = 0
 */
  __pyx_v_matches_pp_fwd = 0;

  /* "pysamstats.pyx":1748
 *     cdef unsigned int matches_pp = 0
 *     cdef unsigned int matches_pp_fwd = 0
 *     cdef unsigned int matches_pp_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int mismatches = 0
 *     cdef unsigned int mismatches_fwd = 0
 */
  __pyx_v_matches_pp_rev = 0;

  /* "pysamstats.pyx":1749
 *     cdef unsigned int matches_pp_fwd = 0
 *     cdef unsigned int matches_pp_rev = 0
 *     cdef unsigned int mismatches = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int mismatches_fwd = 0
 *     cdef unsigned int mismatches_rev = 0
 */
  __pyx_v_mismatches = 0;

  /* "pysamstats.pyx":1750
 *     cdef unsigned int matches_pp_rev = 0
 *     cdef unsigned int mismatches = 0
 *     cdef unsigned int mismatches_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int mismatches_rev = 0
 *     cdef unsigned int mismatches_pp = 0
 */
  __pyx_v_mismatches_fwd = 0;

  /* "pysamstats.pyx":1751
 *     cdef unsigned int mismatches = 0
 *     cdef unsigned int mismatches_fwd = 0
 *     cdef unsigned int mismatches_rev = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int mismatches_pp = 0
 *     cdef unsigned int mismatches_pp_fwd = 0
 */
  __pyx_v_mismatches_rev = 0;

  /* "pysamstats.pyx":1752
 *     cdef unsigned int mismatches_fwd = 0
 *     cdef unsigned int mismatches_rev = 0
 *     cdef unsigned int mismatches_pp = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int mismatches_pp_fwd = 0
 *     cdef unsigned int mismatches_pp_rev = 0
 */
  __pyx_v_mismatches_pp = 0;

  /* "pysamstats.pyx":1753
 *     cdef unsigned int mismatches_rev = 0
 *     cdef unsigned int mismatches_pp = 0
 *     cdef unsigned int mismatches_pp_fwd = 0             # <<<<<<<<<<<<<<
 *     cdef unsigned int mismatches_pp_rev = 0
 * 
 */
  __pyx_v_mismatches_pp_fwd = 0;

  /* "pysamstats.pyx":1754
 *     cdef unsigned int mismatches_pp = 0
 *     cdef unsigned int mismatches_pp_fwd = 0
 *     cdef unsigned int mismatches_pp_rev = 0             # <<<<<<<<<<<<<<
 * 
 *     cdef uint64_t baseq
 */
  __pyx_v_mismatches_pp_rev = 0;

  /* "pysamstats.pyx":1759
 *     cdef uint64_t baseq_squared
 * 
 *     cdef uint64_t baseq_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_fwd_squared_sum = 0
 *     cdef uint64_t baseq_rev_squared_sum = 0
 */
  __pyx_v_baseq_squared_sum = 0;

  /* "pysamstats.pyx":1760
 * 
 *     cdef uint64_t baseq_squared_sum = 0
 *     cdef uint64_t baseq_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_rev_squared_sum = 0
 *     cdef uint64_t baseq_pp_squared_sum = 0
 */
  __pyx_v_baseq_fwd_squared_sum = 0;

  /* "pysamstats.pyx":1761
 *     cdef uint64_t baseq_squared_sum = 0
 *     cdef uint64_t baseq_fwd_squared_sum = 0
 *     cdef uint64_t baseq_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_pp_squared_sum = 0
 *     cdef uint64_t baseq_pp_fwd_squared_sum = 0
 */
  __pyx_v_baseq_rev_squared_sum = 0;

  /* "pysamstats.pyx":1762
 *     cdef uint64_t baseq_fwd_squared_sum = 0
 *     cdef uint64_t baseq_rev_squared_sum = 0
 *     cdef uint64_t baseq_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_pp_fwd_squared_sum = 0
 *     cdef uint64_t baseq_pp_rev_squared_sum = 0
 */
  __pyx_v_baseq_pp_squared_sum = 0;

  /* "pysamstats.pyx":1763
 *     cdef uint64_t baseq_rev_squared_sum = 0
 *     cdef uint64_t baseq_pp_squared_sum = 0
 *     cdef uint64_t baseq_pp_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_pp_rev_squared_sum = 0
 *     cdef uint64_t baseq_matches_squared_sum = 0
 */
  __pyx_v_baseq_pp_fwd_squared_sum = 0;

  /* "pysamstats.pyx":1764
 *     cdef uint64_t baseq_pp_squared_sum = 0
 *     cdef uint64_t baseq_pp_fwd_squared_sum = 0
 *     cdef uint64_t baseq_pp_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_matches_squared_sum = 0
 *     cdef uint64_t baseq_matches_fwd_squared_sum = 0
 */
  __pyx_v_baseq_pp_rev_squared_sum = 0;

  /* "pysamstats.pyx":1765
 *     cdef uint64_t baseq_pp_fwd_squared_sum = 0
 *     cdef uint64_t baseq_pp_rev_squared_sum = 0
 *     cdef uint64_t baseq_matches_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_matches_fwd_squared_sum = 0
 *     cdef uint64_t baseq_matches_rev_squared_sum = 0
 */
  __pyx_v_baseq_matches_squared_sum = 0;

  /* "pysamstats.pyx":1766
 *     cdef uint64_t baseq_pp_rev_squared_sum = 0
 *     cdef uint64_t baseq_matches_squared_sum = 0
 *     cdef uint64_t baseq_matches_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_matches_rev_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_squared_sum = 0
 */
  __pyx_v_baseq_matches_fwd_squared_sum = 0;

  /* "pysamstats.pyx":1767
 *     cdef uint64_t baseq_matches_squared_sum = 0
 *     cdef uint64_t baseq_matches_fwd_squared_sum = 0
 *     cdef uint64_t baseq_matches_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_matches_pp_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_fwd_squared_sum = 0
 */
  __pyx_v_baseq_matches_rev_squared_sum = 0;

  /* "pysamstats.pyx":1768
 *     cdef uint64_t baseq_matches_fwd_squared_sum = 0
 *     cdef uint64_t baseq_matches_rev_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_matches_pp_fwd_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_rev_squared_sum = 0
 */
  __pyx_v_baseq_matches_pp_squared_sum = 0;

  /* "pysamstats.pyx":1769
 *     cdef uint64_t baseq_matches_rev_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_matches_pp_rev_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_squared_sum = 0
 */
  __pyx_v_baseq_matches_pp_fwd_squared_sum = 0;

  /* "pysamstats.pyx":1770
 *     cdef uint64_t baseq_matches_pp_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_fwd_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_mismatches_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_fwd_squared_sum = 0
 */
  __pyx_v_baseq_matches_pp_rev_squared_sum = 0;

  /* "pysamstats.pyx":1771
 *     cdef uint64_t baseq_matches_pp_fwd_squared_sum = 0
 *     cdef uint64_t baseq_matches_pp_rev_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_mismatches_fwd_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_rev_squared_sum = 0
 */
  __pyx_v_baseq_mismatches_squared_sum = 0;

  /* "pysamstats.pyx":1772
 *     cdef uint64_t baseq_matches_pp_rev_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_mismatches_rev_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_pp_squared_sum = 0
 */
  __pyx_v_baseq_mismatches_fwd_squared_sum = 0;

  /* "pysamstats.pyx":1773
 *     cdef uint64_t baseq_mismatches_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_fwd_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_mismatches_pp_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_pp_fwd_squared_sum = 0
 */
  __pyx_v_baseq_mismatches_rev_squared_sum = 0;

  /* "pysamstats.pyx":1774
 *     cdef uint64_t baseq_mismatches_fwd_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_rev_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_pp_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_mismatches_pp_fwd_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_pp_rev_squared_sum = 0
 */
  __pyx_v_baseq_mismatches_pp_squared_sum = 0;

  /* "pysamstats.pyx":1775
 *     cdef uint64_t baseq_mismatches_rev_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_pp_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_pp_fwd_squared_sum = 0             # <<<<<<<<<<<<<<
 *     cdef uint64_t baseq_mismatches_pp_rev_squared_sum = 0
 * 
 */
  __pyx_v_baseq_mismatches_pp_fwd_squared_sum = 0;

  /* "pysamstats.pyx":1776
 *     cdef uint64_t baseq_mismatches_pp_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_pp_fwd_squared_sum = 0
 *     cdef uint64_t baseq_mismatches_pp_rev_squared_sum = 0             # <<<<<<<<<<<<<<
 * 
 *     # initialise variables
 */
  __pyx_v_baseq_mismatches_pp_rev_squared_sum = 0;

  /* "pysamstats.pyx":1779
 * 
 *     # initialise variables
 *     n = col.n             # <<<<<<<<<<<<<<
 *     plp = col.plp
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_col), __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_AsInt(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1779; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;

  /* "pysamstats.pyx":1780
 *     # initialise variables
 *     n = col.n
 *     plp = col.plp             # <<<<<<<<<<<<<<
 * 
 *     # get chromosome name and position
 */
  __pyx_t_3 = __pyx_v_col->plp;
  __pyx_v_plp = __pyx_t_3;

  /* "pysamstats.pyx":1783
 * 
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *     pos = col.pos + 1 if one_based else col.pos
 * 
 */
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyInt_FromLong(__pyx_v_col->tid); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_5), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_v_chrom = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1784
 *     # get chromosome name and position
 *     chrom = samfile.getrname(col.tid)
 *     pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 * 
 *     # reference base
 */
  if (__pyx_v_one_based) {
    __pyx_t_6 = (__pyx_v_col->pos + 1);
  } else {
    __pyx_t_6 = __pyx_v_col->pos;
  }
  __pyx_v_pos = __pyx_t_6;

  /* "pysamstats.pyx":1787
 * 
 *     # reference base
 *     refbase = fafile.fetch(reference=chrom, start=col.pos, end=col.pos+1).upper()             # <<<<<<<<<<<<<<
 * 
 *     # loop over reads, extract what we need
 */
  __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_v_fafile), __pyx_n_s__fetch); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_5));
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__reference), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = PyInt_FromLong(__pyx_v_col->pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__start), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyInt_FromLong((__pyx_v_col->pos + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_5, ((PyObject *)__pyx_n_s__end), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_5)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_5)); __pyx_t_5 = 0;
  __pyx_t_5 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__upper); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1787; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_refbase = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1790
 * 
 *     # loop over reads, extract what we need
 *     for i in range(n):             # <<<<<<<<<<<<<<
 *         read = &(plp[0][i])
 *         aln = read.b
 */
  __pyx_t_2 = __pyx_v_n;
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_2; __pyx_t_7+=1) {
    __pyx_v_i = __pyx_t_7;

    /* "pysamstats.pyx":1791
 *     # loop over reads, extract what we need
 *     for i in range(n):
 *         read = &(plp[0][i])             # <<<<<<<<<<<<<<
 *         aln = read.b
 *         flag = aln.core.flag
 */
    __pyx_v_read = (&((__pyx_v_plp[0])[__pyx_v_i]));

    /* "pysamstats.pyx":1792
 *     for i in range(n):
 *         read = &(plp[0][i])
 *         aln = read.b             # <<<<<<<<<<<<<<
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 */
    __pyx_t_8 = __pyx_v_read->b;
    __pyx_v_aln = __pyx_t_8;

    /* "pysamstats.pyx":1793
 *         read = &(plp[0][i])
 *         aln = read.b
 *         flag = aln.core.flag             # <<<<<<<<<<<<<<
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 */
    __pyx_t_9 = __pyx_v_aln->core.flag;
    __pyx_v_flag = __pyx_t_9;

    /* "pysamstats.pyx":1794
 *         aln = read.b
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)             # <<<<<<<<<<<<<<
 *         is_reverse = <bint>(flag & BAM_FREVERSE)
 * 
 */
    __pyx_v_is_proper_pair = ((int)(__pyx_v_flag & 2));

    /* "pysamstats.pyx":1795
 *         flag = aln.core.flag
 *         is_proper_pair = <bint>(flag & BAM_FPROPER_PAIR)
 *         is_reverse = <bint>(flag & BAM_FREVERSE)             # <<<<<<<<<<<<<<
 * 
 * #        if is_reverse:
 */
    __pyx_v_is_reverse = ((int)(__pyx_v_flag & 16));

    /* "pysamstats.pyx":1808
 * #                reads_pp_fwd += 1
 * 
 *         if not read.is_del:             # <<<<<<<<<<<<<<
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]
 */
    __pyx_t_10 = (!__pyx_v_read->is_del);
    if (__pyx_t_10) {

      /* "pysamstats.pyx":1809
 * 
 *         if not read.is_del:
 *             reads_nodel += 1             # <<<<<<<<<<<<<<
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 */
      __pyx_v_reads_nodel = (__pyx_v_reads_nodel + 1);

      /* "pysamstats.pyx":1810
 *         if not read.is_del:
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]             # <<<<<<<<<<<<<<
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 */
      __pyx_v_baseq = (bam1_qual(__pyx_v_aln)[__pyx_v_read->qpos]);

      /* "pysamstats.pyx":1811
 *             reads_nodel += 1
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2             # <<<<<<<<<<<<<<
 *             baseq_squared_sum += baseq_squared
 *             if is_reverse:
 */
      __pyx_v_baseq_squared = __Pyx_pow_uint64_t(__pyx_v_baseq, 2);

      /* "pysamstats.pyx":1812
 *             baseq = bam1_qual(aln)[read.qpos]
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             if is_reverse:
 *                 reads_rev_nodel += 1
 */
      __pyx_v_baseq_squared_sum = (__pyx_v_baseq_squared_sum + __pyx_v_baseq_squared);

      /* "pysamstats.pyx":1813
 *             baseq_squared = baseq**2
 *             baseq_squared_sum += baseq_squared
 *             if is_reverse:             # <<<<<<<<<<<<<<
 *                 reads_rev_nodel += 1
 *                 baseq_rev_squared_sum += baseq_squared
 */
      if (__pyx_v_is_reverse) {

        /* "pysamstats.pyx":1814
 *             baseq_squared_sum += baseq_squared
 *             if is_reverse:
 *                 reads_rev_nodel += 1             # <<<<<<<<<<<<<<
 *                 baseq_rev_squared_sum += baseq_squared
 *             else:
 */
        __pyx_v_reads_rev_nodel = (__pyx_v_reads_rev_nodel + 1);

        /* "pysamstats.pyx":1815
 *             if is_reverse:
 *                 reads_rev_nodel += 1
 *                 baseq_rev_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             else:
 *                 reads_fwd_nodel += 1
 */
        __pyx_v_baseq_rev_squared_sum = (__pyx_v_baseq_rev_squared_sum + __pyx_v_baseq_squared);
        goto __pyx_L6;
      }
      /*else*/ {

        /* "pysamstats.pyx":1817
 *                 baseq_rev_squared_sum += baseq_squared
 *             else:
 *                 reads_fwd_nodel += 1             # <<<<<<<<<<<<<<
 *                 baseq_fwd_squared_sum += baseq_squared
 *             if is_proper_pair:
 */
        __pyx_v_reads_fwd_nodel = (__pyx_v_reads_fwd_nodel + 1);

        /* "pysamstats.pyx":1818
 *             else:
 *                 reads_fwd_nodel += 1
 *                 baseq_fwd_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1
 */
        __pyx_v_baseq_fwd_squared_sum = (__pyx_v_baseq_fwd_squared_sum + __pyx_v_baseq_squared);
      }
      __pyx_L6:;

      /* "pysamstats.pyx":1819
 *                 reads_fwd_nodel += 1
 *                 baseq_fwd_squared_sum += baseq_squared
 *             if is_proper_pair:             # <<<<<<<<<<<<<<
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared
 */
      if (__pyx_v_is_proper_pair) {

        /* "pysamstats.pyx":1820
 *                 baseq_fwd_squared_sum += baseq_squared
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1             # <<<<<<<<<<<<<<
 *                 baseq_pp_squared_sum += baseq_squared
 *                 if is_reverse:
 */
        __pyx_v_reads_pp_nodel = (__pyx_v_reads_pp_nodel + 1);

        /* "pysamstats.pyx":1821
 *             if is_proper_pair:
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                 if is_reverse:
 *                     reads_pp_rev_nodel += 1
 */
        __pyx_v_baseq_pp_squared_sum = (__pyx_v_baseq_pp_squared_sum + __pyx_v_baseq_squared);

        /* "pysamstats.pyx":1822
 *                 reads_pp_nodel += 1
 *                 baseq_pp_squared_sum += baseq_squared
 *                 if is_reverse:             # <<<<<<<<<<<<<<
 *                     reads_pp_rev_nodel += 1
 *                     baseq_pp_rev_squared_sum += baseq_squared
 */
        if (__pyx_v_is_reverse) {

          /* "pysamstats.pyx":1823
 *                 baseq_pp_squared_sum += baseq_squared
 *                 if is_reverse:
 *                     reads_pp_rev_nodel += 1             # <<<<<<<<<<<<<<
 *                     baseq_pp_rev_squared_sum += baseq_squared
 *                 else:
 */
          __pyx_v_reads_pp_rev_nodel = (__pyx_v_reads_pp_rev_nodel + 1);

          /* "pysamstats.pyx":1824
 *                 if is_reverse:
 *                     reads_pp_rev_nodel += 1
 *                     baseq_pp_rev_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                 else:
 *                     reads_pp_fwd_nodel += 1
 */
          __pyx_v_baseq_pp_rev_squared_sum = (__pyx_v_baseq_pp_rev_squared_sum + __pyx_v_baseq_squared);
          goto __pyx_L8;
        }
        /*else*/ {

          /* "pysamstats.pyx":1826
 *                     baseq_pp_rev_squared_sum += baseq_squared
 *                 else:
 *                     reads_pp_fwd_nodel += 1             # <<<<<<<<<<<<<<
 *                     baseq_pp_fwd_squared_sum += baseq_squared
 *             alnbase = get_seq_base(aln, read.qpos)
 */
          __pyx_v_reads_pp_fwd_nodel = (__pyx_v_reads_pp_fwd_nodel + 1);

          /* "pysamstats.pyx":1827
 *                 else:
 *                     reads_pp_fwd_nodel += 1
 *                     baseq_pp_fwd_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             alnbase = get_seq_base(aln, read.qpos)
 *             if alnbase == refbase:
 */
          __pyx_v_baseq_pp_fwd_squared_sum = (__pyx_v_baseq_pp_fwd_squared_sum + __pyx_v_baseq_squared);
        }
        __pyx_L8:;
        goto __pyx_L7;
      }
      __pyx_L7:;

      /* "pysamstats.pyx":1828
 *                     reads_pp_fwd_nodel += 1
 *                     baseq_pp_fwd_squared_sum += baseq_squared
 *             alnbase = get_seq_base(aln, read.qpos)             # <<<<<<<<<<<<<<
 *             if alnbase == refbase:
 *                 matches += 1
 */
      __pyx_t_1 = __pyx_f_10pysamstats_get_seq_base(__pyx_v_aln, __pyx_v_read->qpos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_v_alnbase);
      __pyx_v_alnbase = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "pysamstats.pyx":1829
 *                     baseq_pp_fwd_squared_sum += baseq_squared
 *             alnbase = get_seq_base(aln, read.qpos)
 *             if alnbase == refbase:             # <<<<<<<<<<<<<<
 *                 matches += 1
 *                 baseq_matches_squared_sum += baseq_squared
 */
      __pyx_t_1 = PyObject_RichCompare(__pyx_v_alnbase, __pyx_v_refbase, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_10) {

        /* "pysamstats.pyx":1830
 *             alnbase = get_seq_base(aln, read.qpos)
 *             if alnbase == refbase:
 *                 matches += 1             # <<<<<<<<<<<<<<
 *                 baseq_matches_squared_sum += baseq_squared
 *                 if is_reverse:
 */
        __pyx_v_matches = (__pyx_v_matches + 1);

        /* "pysamstats.pyx":1831
 *             if alnbase == refbase:
 *                 matches += 1
 *                 baseq_matches_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                 if is_reverse:
 *                     matches_rev += 1
 */
        __pyx_v_baseq_matches_squared_sum = (__pyx_v_baseq_matches_squared_sum + __pyx_v_baseq_squared);

        /* "pysamstats.pyx":1832
 *                 matches += 1
 *                 baseq_matches_squared_sum += baseq_squared
 *                 if is_reverse:             # <<<<<<<<<<<<<<
 *                     matches_rev += 1
 *                     baseq_matches_rev_squared_sum += baseq_squared
 */
        if (__pyx_v_is_reverse) {

          /* "pysamstats.pyx":1833
 *                 baseq_matches_squared_sum += baseq_squared
 *                 if is_reverse:
 *                     matches_rev += 1             # <<<<<<<<<<<<<<
 *                     baseq_matches_rev_squared_sum += baseq_squared
 *                 else:
 */
          __pyx_v_matches_rev = (__pyx_v_matches_rev + 1);

          /* "pysamstats.pyx":1834
 *                 if is_reverse:
 *                     matches_rev += 1
 *                     baseq_matches_rev_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                 else:
 *                     matches_fwd += 1
 */
          __pyx_v_baseq_matches_rev_squared_sum = (__pyx_v_baseq_matches_rev_squared_sum + __pyx_v_baseq_squared);
          goto __pyx_L10;
        }
        /*else*/ {

          /* "pysamstats.pyx":1836
 *                     baseq_matches_rev_squared_sum += baseq_squared
 *                 else:
 *                     matches_fwd += 1             # <<<<<<<<<<<<<<
 *                     baseq_matches_fwd_squared_sum += baseq_squared
 * 
 */
          __pyx_v_matches_fwd = (__pyx_v_matches_fwd + 1);

          /* "pysamstats.pyx":1837
 *                 else:
 *                     matches_fwd += 1
 *                     baseq_matches_fwd_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 * 
 *                 if is_proper_pair:
 */
          __pyx_v_baseq_matches_fwd_squared_sum = (__pyx_v_baseq_matches_fwd_squared_sum + __pyx_v_baseq_squared);
        }
        __pyx_L10:;

        /* "pysamstats.pyx":1839
 *                     baseq_matches_fwd_squared_sum += baseq_squared
 * 
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     matches_pp += 1
 *                     baseq_matches_pp_squared_sum += baseq_squared
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":1840
 * 
 *                 if is_proper_pair:
 *                     matches_pp += 1             # <<<<<<<<<<<<<<
 *                     baseq_matches_pp_squared_sum += baseq_squared
 *                     if is_reverse:
 */
          __pyx_v_matches_pp = (__pyx_v_matches_pp + 1);

          /* "pysamstats.pyx":1841
 *                 if is_proper_pair:
 *                     matches_pp += 1
 *                     baseq_matches_pp_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                     if is_reverse:
 *                         matches_pp_rev += 1
 */
          __pyx_v_baseq_matches_pp_squared_sum = (__pyx_v_baseq_matches_pp_squared_sum + __pyx_v_baseq_squared);

          /* "pysamstats.pyx":1842
 *                     matches_pp += 1
 *                     baseq_matches_pp_squared_sum += baseq_squared
 *                     if is_reverse:             # <<<<<<<<<<<<<<
 *                         matches_pp_rev += 1
 *                         baseq_matches_pp_rev_squared_sum += baseq_squared
 */
          if (__pyx_v_is_reverse) {

            /* "pysamstats.pyx":1843
 *                     baseq_matches_pp_squared_sum += baseq_squared
 *                     if is_reverse:
 *                         matches_pp_rev += 1             # <<<<<<<<<<<<<<
 *                         baseq_matches_pp_rev_squared_sum += baseq_squared
 *                     else:
 */
            __pyx_v_matches_pp_rev = (__pyx_v_matches_pp_rev + 1);

            /* "pysamstats.pyx":1844
 *                     if is_reverse:
 *                         matches_pp_rev += 1
 *                         baseq_matches_pp_rev_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                     else:
 *                         matches_pp_fwd += 1
 */
            __pyx_v_baseq_matches_pp_rev_squared_sum = (__pyx_v_baseq_matches_pp_rev_squared_sum + __pyx_v_baseq_squared);
            goto __pyx_L12;
          }
          /*else*/ {

            /* "pysamstats.pyx":1846
 *                         baseq_matches_pp_rev_squared_sum += baseq_squared
 *                     else:
 *                         matches_pp_fwd += 1             # <<<<<<<<<<<<<<
 *                         baseq_matches_pp_fwd_squared_sum += baseq_squared
 *             else:
 */
            __pyx_v_matches_pp_fwd = (__pyx_v_matches_pp_fwd + 1);

            /* "pysamstats.pyx":1847
 *                     else:
 *                         matches_pp_fwd += 1
 *                         baseq_matches_pp_fwd_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *             else:
 *                 mismatches += 1
 */
            __pyx_v_baseq_matches_pp_fwd_squared_sum = (__pyx_v_baseq_matches_pp_fwd_squared_sum + __pyx_v_baseq_squared);
          }
          __pyx_L12:;
          goto __pyx_L11;
        }
        __pyx_L11:;
        goto __pyx_L9;
      }
      /*else*/ {

        /* "pysamstats.pyx":1849
 *                         baseq_matches_pp_fwd_squared_sum += baseq_squared
 *             else:
 *                 mismatches += 1             # <<<<<<<<<<<<<<
 *                 baseq_mismatches_squared_sum += baseq_squared
 *                 if is_reverse:
 */
        __pyx_v_mismatches = (__pyx_v_mismatches + 1);

        /* "pysamstats.pyx":1850
 *             else:
 *                 mismatches += 1
 *                 baseq_mismatches_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                 if is_reverse:
 *                     mismatches_rev += 1
 */
        __pyx_v_baseq_mismatches_squared_sum = (__pyx_v_baseq_mismatches_squared_sum + __pyx_v_baseq_squared);

        /* "pysamstats.pyx":1851
 *                 mismatches += 1
 *                 baseq_mismatches_squared_sum += baseq_squared
 *                 if is_reverse:             # <<<<<<<<<<<<<<
 *                     mismatches_rev += 1
 *                     baseq_mismatches_rev_squared_sum += baseq_squared
 */
        if (__pyx_v_is_reverse) {

          /* "pysamstats.pyx":1852
 *                 baseq_mismatches_squared_sum += baseq_squared
 *                 if is_reverse:
 *                     mismatches_rev += 1             # <<<<<<<<<<<<<<
 *                     baseq_mismatches_rev_squared_sum += baseq_squared
 *                 else:
 */
          __pyx_v_mismatches_rev = (__pyx_v_mismatches_rev + 1);

          /* "pysamstats.pyx":1853
 *                 if is_reverse:
 *                     mismatches_rev += 1
 *                     baseq_mismatches_rev_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                 else:
 *                     mismatches_fwd += 1
 */
          __pyx_v_baseq_mismatches_rev_squared_sum = (__pyx_v_baseq_mismatches_rev_squared_sum + __pyx_v_baseq_squared);
          goto __pyx_L13;
        }
        /*else*/ {

          /* "pysamstats.pyx":1855
 *                     baseq_mismatches_rev_squared_sum += baseq_squared
 *                 else:
 *                     mismatches_fwd += 1             # <<<<<<<<<<<<<<
 *                     baseq_mismatches_fwd_squared_sum += baseq_squared
 * 
 */
          __pyx_v_mismatches_fwd = (__pyx_v_mismatches_fwd + 1);

          /* "pysamstats.pyx":1856
 *                 else:
 *                     mismatches_fwd += 1
 *                     baseq_mismatches_fwd_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 * 
 *                 if is_proper_pair:
 */
          __pyx_v_baseq_mismatches_fwd_squared_sum = (__pyx_v_baseq_mismatches_fwd_squared_sum + __pyx_v_baseq_squared);
        }
        __pyx_L13:;

        /* "pysamstats.pyx":1858
 *                     baseq_mismatches_fwd_squared_sum += baseq_squared
 * 
 *                 if is_proper_pair:             # <<<<<<<<<<<<<<
 *                     mismatches_pp += 1
 *                     baseq_mismatches_pp_squared_sum += baseq_squared
 */
        if (__pyx_v_is_proper_pair) {

          /* "pysamstats.pyx":1859
 * 
 *                 if is_proper_pair:
 *                     mismatches_pp += 1             # <<<<<<<<<<<<<<
 *                     baseq_mismatches_pp_squared_sum += baseq_squared
 *                     if is_reverse:
 */
          __pyx_v_mismatches_pp = (__pyx_v_mismatches_pp + 1);

          /* "pysamstats.pyx":1860
 *                 if is_proper_pair:
 *                     mismatches_pp += 1
 *                     baseq_mismatches_pp_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                     if is_reverse:
 *                         mismatches_pp_rev += 1
 */
          __pyx_v_baseq_mismatches_pp_squared_sum = (__pyx_v_baseq_mismatches_pp_squared_sum + __pyx_v_baseq_squared);

          /* "pysamstats.pyx":1861
 *                     mismatches_pp += 1
 *                     baseq_mismatches_pp_squared_sum += baseq_squared
 *                     if is_reverse:             # <<<<<<<<<<<<<<
 *                         mismatches_pp_rev += 1
 *                         baseq_mismatches_pp_rev_squared_sum += baseq_squared
 */
          if (__pyx_v_is_reverse) {

            /* "pysamstats.pyx":1862
 *                     baseq_mismatches_pp_squared_sum += baseq_squared
 *                     if is_reverse:
 *                         mismatches_pp_rev += 1             # <<<<<<<<<<<<<<
 *                         baseq_mismatches_pp_rev_squared_sum += baseq_squared
 *                     else:
 */
            __pyx_v_mismatches_pp_rev = (__pyx_v_mismatches_pp_rev + 1);

            /* "pysamstats.pyx":1863
 *                     if is_reverse:
 *                         mismatches_pp_rev += 1
 *                         baseq_mismatches_pp_rev_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 *                     else:
 *                         mismatches_pp_fwd += 1
 */
            __pyx_v_baseq_mismatches_pp_rev_squared_sum = (__pyx_v_baseq_mismatches_pp_rev_squared_sum + __pyx_v_baseq_squared);
            goto __pyx_L15;
          }
          /*else*/ {

            /* "pysamstats.pyx":1865
 *                         baseq_mismatches_pp_rev_squared_sum += baseq_squared
 *                     else:
 *                         mismatches_pp_fwd += 1             # <<<<<<<<<<<<<<
 *                         baseq_mismatches_pp_fwd_squared_sum += baseq_squared
 * 
 */
            __pyx_v_mismatches_pp_fwd = (__pyx_v_mismatches_pp_fwd + 1);

            /* "pysamstats.pyx":1866
 *                     else:
 *                         mismatches_pp_fwd += 1
 *                         baseq_mismatches_pp_fwd_squared_sum += baseq_squared             # <<<<<<<<<<<<<<
 * 
 *     # construct output variables
 */
            __pyx_v_baseq_mismatches_pp_fwd_squared_sum = (__pyx_v_baseq_mismatches_pp_fwd_squared_sum + __pyx_v_baseq_squared);
          }
          __pyx_L15:;
          goto __pyx_L14;
        }
        __pyx_L14:;
      }
      __pyx_L9:;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  /* "pysamstats.pyx":1869
 * 
 *     # construct output variables
 *     rms_baseq = rootmean(baseq_squared_sum, reads_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_fwd = rootmean(baseq_fwd_squared_sum, reads_fwd_nodel)
 *     rms_baseq_rev = rootmean(baseq_rev_squared_sum, reads_rev_nodel)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_squared_sum, __pyx_v_reads_nodel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1870
 *     # construct output variables
 *     rms_baseq = rootmean(baseq_squared_sum, reads_nodel)
 *     rms_baseq_fwd = rootmean(baseq_fwd_squared_sum, reads_fwd_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_rev = rootmean(baseq_rev_squared_sum, reads_rev_nodel)
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_fwd_squared_sum, __pyx_v_reads_fwd_nodel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_fwd = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1871
 *     rms_baseq = rootmean(baseq_squared_sum, reads_nodel)
 *     rms_baseq_fwd = rootmean(baseq_fwd_squared_sum, reads_fwd_nodel)
 *     rms_baseq_rev = rootmean(baseq_rev_squared_sum, reads_rev_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 *     rms_baseq_pp_fwd = rootmean(baseq_pp_fwd_squared_sum, reads_pp_fwd_nodel)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_rev_squared_sum, __pyx_v_reads_rev_nodel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_rev = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1872
 *     rms_baseq_fwd = rootmean(baseq_fwd_squared_sum, reads_fwd_nodel)
 *     rms_baseq_rev = rootmean(baseq_rev_squared_sum, reads_rev_nodel)
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_pp_fwd = rootmean(baseq_pp_fwd_squared_sum, reads_pp_fwd_nodel)
 *     rms_baseq_pp_rev = rootmean(baseq_pp_rev_squared_sum, reads_pp_rev_nodel)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_pp_squared_sum, __pyx_v_reads_pp_nodel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_pp = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1873
 *     rms_baseq_rev = rootmean(baseq_rev_squared_sum, reads_rev_nodel)
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 *     rms_baseq_pp_fwd = rootmean(baseq_pp_fwd_squared_sum, reads_pp_fwd_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_pp_rev = rootmean(baseq_pp_rev_squared_sum, reads_pp_rev_nodel)
 *     rms_baseq_matches = rootmean(baseq_matches_squared_sum, matches)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_pp_fwd_squared_sum, __pyx_v_reads_pp_fwd_nodel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_pp_fwd = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1874
 *     rms_baseq_pp = rootmean(baseq_pp_squared_sum, reads_pp_nodel)
 *     rms_baseq_pp_fwd = rootmean(baseq_pp_fwd_squared_sum, reads_pp_fwd_nodel)
 *     rms_baseq_pp_rev = rootmean(baseq_pp_rev_squared_sum, reads_pp_rev_nodel)             # <<<<<<<<<<<<<<
 *     rms_baseq_matches = rootmean(baseq_matches_squared_sum, matches)
 *     rms_baseq_matches_fwd = rootmean(baseq_matches_fwd_squared_sum, matches_fwd)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_pp_rev_squared_sum, __pyx_v_reads_pp_rev_nodel); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1874; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_pp_rev = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1875
 *     rms_baseq_pp_fwd = rootmean(baseq_pp_fwd_squared_sum, reads_pp_fwd_nodel)
 *     rms_baseq_pp_rev = rootmean(baseq_pp_rev_squared_sum, reads_pp_rev_nodel)
 *     rms_baseq_matches = rootmean(baseq_matches_squared_sum, matches)             # <<<<<<<<<<<<<<
 *     rms_baseq_matches_fwd = rootmean(baseq_matches_fwd_squared_sum, matches_fwd)
 *     rms_baseq_matches_rev = rootmean(baseq_matches_rev_squared_sum, matches_rev)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_matches_squared_sum, __pyx_v_matches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_matches = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1876
 *     rms_baseq_pp_rev = rootmean(baseq_pp_rev_squared_sum, reads_pp_rev_nodel)
 *     rms_baseq_matches = rootmean(baseq_matches_squared_sum, matches)
 *     rms_baseq_matches_fwd = rootmean(baseq_matches_fwd_squared_sum, matches_fwd)             # <<<<<<<<<<<<<<
 *     rms_baseq_matches_rev = rootmean(baseq_matches_rev_squared_sum, matches_rev)
 *     rms_baseq_matches_pp = rootmean(baseq_matches_pp_squared_sum, matches_pp)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_matches_fwd_squared_sum, __pyx_v_matches_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_matches_fwd = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1877
 *     rms_baseq_matches = rootmean(baseq_matches_squared_sum, matches)
 *     rms_baseq_matches_fwd = rootmean(baseq_matches_fwd_squared_sum, matches_fwd)
 *     rms_baseq_matches_rev = rootmean(baseq_matches_rev_squared_sum, matches_rev)             # <<<<<<<<<<<<<<
 *     rms_baseq_matches_pp = rootmean(baseq_matches_pp_squared_sum, matches_pp)
 *     rms_baseq_matches_pp_fwd = rootmean(baseq_matches_pp_fwd_squared_sum, matches_pp_fwd)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_matches_rev_squared_sum, __pyx_v_matches_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_matches_rev = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1878
 *     rms_baseq_matches_fwd = rootmean(baseq_matches_fwd_squared_sum, matches_fwd)
 *     rms_baseq_matches_rev = rootmean(baseq_matches_rev_squared_sum, matches_rev)
 *     rms_baseq_matches_pp = rootmean(baseq_matches_pp_squared_sum, matches_pp)             # <<<<<<<<<<<<<<
 *     rms_baseq_matches_pp_fwd = rootmean(baseq_matches_pp_fwd_squared_sum, matches_pp_fwd)
 *     rms_baseq_matches_pp_rev = rootmean(baseq_matches_pp_rev_squared_sum, matches_pp_rev)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_matches_pp_squared_sum, __pyx_v_matches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1878; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_matches_pp = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1879
 *     rms_baseq_matches_rev = rootmean(baseq_matches_rev_squared_sum, matches_rev)
 *     rms_baseq_matches_pp = rootmean(baseq_matches_pp_squared_sum, matches_pp)
 *     rms_baseq_matches_pp_fwd = rootmean(baseq_matches_pp_fwd_squared_sum, matches_pp_fwd)             # <<<<<<<<<<<<<<
 *     rms_baseq_matches_pp_rev = rootmean(baseq_matches_pp_rev_squared_sum, matches_pp_rev)
 *     rms_baseq_mismatches = rootmean(baseq_mismatches_squared_sum, mismatches)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_matches_pp_fwd_squared_sum, __pyx_v_matches_pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1879; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_matches_pp_fwd = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1880
 *     rms_baseq_matches_pp = rootmean(baseq_matches_pp_squared_sum, matches_pp)
 *     rms_baseq_matches_pp_fwd = rootmean(baseq_matches_pp_fwd_squared_sum, matches_pp_fwd)
 *     rms_baseq_matches_pp_rev = rootmean(baseq_matches_pp_rev_squared_sum, matches_pp_rev)             # <<<<<<<<<<<<<<
 *     rms_baseq_mismatches = rootmean(baseq_mismatches_squared_sum, mismatches)
 *     rms_baseq_mismatches_fwd = rootmean(baseq_mismatches_fwd_squared_sum, mismatches_fwd)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_matches_pp_rev_squared_sum, __pyx_v_matches_pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_matches_pp_rev = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1881
 *     rms_baseq_matches_pp_fwd = rootmean(baseq_matches_pp_fwd_squared_sum, matches_pp_fwd)
 *     rms_baseq_matches_pp_rev = rootmean(baseq_matches_pp_rev_squared_sum, matches_pp_rev)
 *     rms_baseq_mismatches = rootmean(baseq_mismatches_squared_sum, mismatches)             # <<<<<<<<<<<<<<
 *     rms_baseq_mismatches_fwd = rootmean(baseq_mismatches_fwd_squared_sum, mismatches_fwd)
 *     rms_baseq_mismatches_rev = rootmean(baseq_mismatches_rev_squared_sum, mismatches_rev)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_mismatches_squared_sum, __pyx_v_mismatches); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_mismatches = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1882
 *     rms_baseq_matches_pp_rev = rootmean(baseq_matches_pp_rev_squared_sum, matches_pp_rev)
 *     rms_baseq_mismatches = rootmean(baseq_mismatches_squared_sum, mismatches)
 *     rms_baseq_mismatches_fwd = rootmean(baseq_mismatches_fwd_squared_sum, mismatches_fwd)             # <<<<<<<<<<<<<<
 *     rms_baseq_mismatches_rev = rootmean(baseq_mismatches_rev_squared_sum, mismatches_rev)
 *     rms_baseq_mismatches_pp = rootmean(baseq_mismatches_pp_squared_sum, mismatches_pp)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_mismatches_fwd_squared_sum, __pyx_v_mismatches_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_mismatches_fwd = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1883
 *     rms_baseq_mismatches = rootmean(baseq_mismatches_squared_sum, mismatches)
 *     rms_baseq_mismatches_fwd = rootmean(baseq_mismatches_fwd_squared_sum, mismatches_fwd)
 *     rms_baseq_mismatches_rev = rootmean(baseq_mismatches_rev_squared_sum, mismatches_rev)             # <<<<<<<<<<<<<<
 *     rms_baseq_mismatches_pp = rootmean(baseq_mismatches_pp_squared_sum, mismatches_pp)
 *     rms_baseq_mismatches_pp_fwd = rootmean(baseq_mismatches_pp_fwd_squared_sum, mismatches_pp_fwd)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_mismatches_rev_squared_sum, __pyx_v_mismatches_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_mismatches_rev = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1884
 *     rms_baseq_mismatches_fwd = rootmean(baseq_mismatches_fwd_squared_sum, mismatches_fwd)
 *     rms_baseq_mismatches_rev = rootmean(baseq_mismatches_rev_squared_sum, mismatches_rev)
 *     rms_baseq_mismatches_pp = rootmean(baseq_mismatches_pp_squared_sum, mismatches_pp)             # <<<<<<<<<<<<<<
 *     rms_baseq_mismatches_pp_fwd = rootmean(baseq_mismatches_pp_fwd_squared_sum, mismatches_pp_fwd)
 *     rms_baseq_mismatches_pp_rev = rootmean(baseq_mismatches_pp_rev_squared_sum, mismatches_pp_rev)
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_mismatches_pp_squared_sum, __pyx_v_mismatches_pp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1884; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_mismatches_pp = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1885
 *     rms_baseq_mismatches_rev = rootmean(baseq_mismatches_rev_squared_sum, mismatches_rev)
 *     rms_baseq_mismatches_pp = rootmean(baseq_mismatches_pp_squared_sum, mismatches_pp)
 *     rms_baseq_mismatches_pp_fwd = rootmean(baseq_mismatches_pp_fwd_squared_sum, mismatches_pp_fwd)             # <<<<<<<<<<<<<<
 *     rms_baseq_mismatches_pp_rev = rootmean(baseq_mismatches_pp_rev_squared_sum, mismatches_pp_rev)
 * 
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_mismatches_pp_fwd_squared_sum, __pyx_v_mismatches_pp_fwd); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1885; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_mismatches_pp_fwd = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1886
 *     rms_baseq_mismatches_pp = rootmean(baseq_mismatches_pp_squared_sum, mismatches_pp)
 *     rms_baseq_mismatches_pp_fwd = rootmean(baseq_mismatches_pp_fwd_squared_sum, mismatches_pp_fwd)
 *     rms_baseq_mismatches_pp_rev = rootmean(baseq_mismatches_pp_rev_squared_sum, mismatches_pp_rev)             # <<<<<<<<<<<<<<
 * 
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,
 */
  __pyx_t_1 = __pyx_f_10pysamstats_rootmean(__pyx_v_baseq_mismatches_pp_rev_squared_sum, __pyx_v_mismatches_pp_rev); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1886; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rms_baseq_mismatches_pp_rev = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1888
 *     rms_baseq_mismatches_pp_rev = rootmean(baseq_mismatches_pp_rev_squared_sum, mismatches_pp_rev)
 * 
 *     return {'chrom': chrom, 'pos': pos, 'ref': refbase,             # <<<<<<<<<<<<<<
 * #            'reads_all': n, 'reads_fwd': reads_fwd, 'reads_rev': reads_rev,
 * #            'reads_pp': reads_pp, 'reads_pp_fwd': reads_pp_fwd, 'reads_pp_rev': reads_pp_rev,
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = PyInt_FromLong(__pyx_v_pos); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__pos), __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__ref), __pyx_v_refbase) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1895
 * #            'mismatches': mismatches, 'mismatches_fwd': mismatches_fwd, 'mismatches_rev': mismatches_rev,
 * #            'mismatches_pp': mismatches_pp, 'mismatches_pp_fwd': mismatches_pp_fwd, 'mismatches_pp_rev': mismatches_pp_rev,
 *             'rms_baseq': rms_baseq, 'rms_baseq_fwd': rms_baseq_fwd, 'rms_baseq_rev': rms_baseq_rev,             # <<<<<<<<<<<<<<
 *             'rms_baseq_pp': rms_baseq_pp, 'rms_baseq_pp_fwd': rms_baseq_pp_fwd, 'rms_baseq_pp_rev': rms_baseq_pp_rev,
 *             'rms_baseq_matches': rms_baseq_matches, 'rms_baseq_matches_fwd': rms_baseq_matches_fwd, 'rms_baseq_matches_rev': rms_baseq_matches_rev,
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__rms_baseq), __pyx_v_rms_baseq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__rms_baseq_fwd), __pyx_v_rms_baseq_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__rms_baseq_rev), __pyx_v_rms_baseq_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1896
 * #            'mismatches_pp': mismatches_pp, 'mismatches_pp_fwd': mismatches_pp_fwd, 'mismatches_pp_rev': mismatches_pp_rev,
 *             'rms_baseq': rms_baseq, 'rms_baseq_fwd': rms_baseq_fwd, 'rms_baseq_rev': rms_baseq_rev,
 *             'rms_baseq_pp': rms_baseq_pp, 'rms_baseq_pp_fwd': rms_baseq_pp_fwd, 'rms_baseq_pp_rev': rms_baseq_pp_rev,             # <<<<<<<<<<<<<<
 *             'rms_baseq_matches': rms_baseq_matches, 'rms_baseq_matches_fwd': rms_baseq_matches_fwd, 'rms_baseq_matches_rev': rms_baseq_matches_rev,
 *             'rms_baseq_matches_pp': rms_baseq_matches_pp, 'rms_baseq_matches_pp_fwd': rms_baseq_matches_pp_fwd, 'rms_baseq_matches_pp_rev': rms_baseq_matches_pp_rev,
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__rms_baseq_pp), __pyx_v_rms_baseq_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__rms_baseq_pp_fwd), __pyx_v_rms_baseq_pp_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__rms_baseq_pp_rev), __pyx_v_rms_baseq_pp_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1897
 *             'rms_baseq': rms_baseq, 'rms_baseq_fwd': rms_baseq_fwd, 'rms_baseq_rev': rms_baseq_rev,
 *             'rms_baseq_pp': rms_baseq_pp, 'rms_baseq_pp_fwd': rms_baseq_pp_fwd, 'rms_baseq_pp_rev': rms_baseq_pp_rev,
 *             'rms_baseq_matches': rms_baseq_matches, 'rms_baseq_matches_fwd': rms_baseq_matches_fwd, 'rms_baseq_matches_rev': rms_baseq_matches_rev,             # <<<<<<<<<<<<<<
 *             'rms_baseq_matches_pp': rms_baseq_matches_pp, 'rms_baseq_matches_pp_fwd': rms_baseq_matches_pp_fwd, 'rms_baseq_matches_pp_rev': rms_baseq_matches_pp_rev,
 *             'rms_baseq_mismatches': rms_baseq_mismatches, 'rms_baseq_mismatches_fwd': rms_baseq_mismatches_fwd, 'rms_baseq_mismatches_rev': rms_baseq_mismatches_rev,
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__rms_baseq_matches), __pyx_v_rms_baseq_matches) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_43), __pyx_v_rms_baseq_matches_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_44), __pyx_v_rms_baseq_matches_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1898
 *             'rms_baseq_pp': rms_baseq_pp, 'rms_baseq_pp_fwd': rms_baseq_pp_fwd, 'rms_baseq_pp_rev': rms_baseq_pp_rev,
 *             'rms_baseq_matches': rms_baseq_matches, 'rms_baseq_matches_fwd': rms_baseq_matches_fwd, 'rms_baseq_matches_rev': rms_baseq_matches_rev,
 *             'rms_baseq_matches_pp': rms_baseq_matches_pp, 'rms_baseq_matches_pp_fwd': rms_baseq_matches_pp_fwd, 'rms_baseq_matches_pp_rev': rms_baseq_matches_pp_rev,             # <<<<<<<<<<<<<<
 *             'rms_baseq_mismatches': rms_baseq_mismatches, 'rms_baseq_mismatches_fwd': rms_baseq_mismatches_fwd, 'rms_baseq_mismatches_rev': rms_baseq_mismatches_rev,
 *             'rms_baseq_mismatches_pp': rms_baseq_mismatches_pp, 'rms_baseq_mismatches_pp_fwd': rms_baseq_mismatches_pp_fwd, 'rms_baseq_mismatches_pp_rev': rms_baseq_mismatches_pp_rev,
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_38), __pyx_v_rms_baseq_matches_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_45), __pyx_v_rms_baseq_matches_pp_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_46), __pyx_v_rms_baseq_matches_pp_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1899
 *             'rms_baseq_matches': rms_baseq_matches, 'rms_baseq_matches_fwd': rms_baseq_matches_fwd, 'rms_baseq_matches_rev': rms_baseq_matches_rev,
 *             'rms_baseq_matches_pp': rms_baseq_matches_pp, 'rms_baseq_matches_pp_fwd': rms_baseq_matches_pp_fwd, 'rms_baseq_matches_pp_rev': rms_baseq_matches_pp_rev,
 *             'rms_baseq_mismatches': rms_baseq_mismatches, 'rms_baseq_mismatches_fwd': rms_baseq_mismatches_fwd, 'rms_baseq_mismatches_rev': rms_baseq_mismatches_rev,             # <<<<<<<<<<<<<<
 *             'rms_baseq_mismatches_pp': rms_baseq_mismatches_pp, 'rms_baseq_mismatches_pp_fwd': rms_baseq_mismatches_pp_fwd, 'rms_baseq_mismatches_pp_rev': rms_baseq_mismatches_pp_rev,
 *             }
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_39), __pyx_v_rms_baseq_mismatches) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_47), __pyx_v_rms_baseq_mismatches_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_48), __pyx_v_rms_baseq_mismatches_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1900
 *             'rms_baseq_matches_pp': rms_baseq_matches_pp, 'rms_baseq_matches_pp_fwd': rms_baseq_matches_pp_fwd, 'rms_baseq_matches_pp_rev': rms_baseq_matches_pp_rev,
 *             'rms_baseq_mismatches': rms_baseq_mismatches, 'rms_baseq_mismatches_fwd': rms_baseq_mismatches_fwd, 'rms_baseq_mismatches_rev': rms_baseq_mismatches_rev,
 *             'rms_baseq_mismatches_pp': rms_baseq_mismatches_pp, 'rms_baseq_mismatches_pp_fwd': rms_baseq_mismatches_pp_fwd, 'rms_baseq_mismatches_pp_rev': rms_baseq_mismatches_pp_rev,             # <<<<<<<<<<<<<<
 *             }
 * 
 */
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_40), __pyx_v_rms_baseq_mismatches_pp) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_49), __pyx_v_rms_baseq_mismatches_pp_fwd) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s_50), __pyx_v_rms_baseq_mismatches_pp_rev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_chrom);
  __Pyx_XDECREF(__pyx_v_refbase);
  __Pyx_XDECREF(__pyx_v_alnbase);
  __Pyx_XDECREF(__pyx_v_rms_baseq);
  __Pyx_XDECREF(__pyx_v_rms_baseq_fwd);
  __Pyx_XDECREF(__pyx_v_rms_baseq_rev);
  __Pyx_XDECREF(__pyx_v_rms_baseq_pp);
  __Pyx_XDECREF(__pyx_v_rms_baseq_pp_fwd);
  __Pyx_XDECREF(__pyx_v_rms_baseq_pp_rev);
  __Pyx_XDECREF(__pyx_v_rms_baseq_matches);
  __Pyx_XDECREF(__pyx_v_rms_baseq_matches_fwd);
  __Pyx_XDECREF(__pyx_v_rms_baseq_matches_rev);
  __Pyx_XDECREF(__pyx_v_rms_baseq_matches_pp);
  __Pyx_XDECREF(__pyx_v_rms_baseq_matches_pp_fwd);
  __Pyx_XDECREF(__pyx_v_rms_baseq_matches_pp_rev);
  __Pyx_XDECREF(__pyx_v_rms_baseq_mismatches);
  __Pyx_XDECREF(__pyx_v_rms_baseq_mismatches_fwd);
  __Pyx_XDECREF(__pyx_v_rms_baseq_mismatches_rev);
  __Pyx_XDECREF(__pyx_v_rms_baseq_mismatches_pp);
  __Pyx_XDECREF(__pyx_v_rms_baseq_mismatches_pp_fwd);
  __Pyx_XDECREF(__pyx_v_rms_baseq_mismatches_pp_rev);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_92construct_rec_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_pw_10pysamstats_92construct_rec_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile = 0;
  struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col = 0;
  int __pyx_v_one_based;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("construct_rec_baseq_ext_strand (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__samfile,&__pyx_n_s__fafile,&__pyx_n_s__col,&__pyx_n_s__one_based,0};
    PyObject* values[4] = {0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_baseq_ext_strand", 0, 3, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__col)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("construct_rec_baseq_ext_strand", 0, 3, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "construct_rec_baseq_ext_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __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);
        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_9csamtools_Samfile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)values[1]);
    __pyx_v_col = ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)values[2]);
    if (values[3]) {
      __pyx_v_one_based = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_one_based == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1719; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
    } else {

      /* "pysamstats.pyx":1719
 * 
 * cpdef object construct_rec_baseq_ext_strand(Samfile samfile, Fastafile fafile,
 *                                             PileupProxy col, bint one_based=False):             # <<<<<<<<<<<<<<
 * 
 *     # statically typed variables
 */
      __pyx_v_one_based = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("construct_rec_baseq_ext_strand", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_col), __pyx_ptype_5pysam_9csamtools_PileupProxy, 1, "col", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1719; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_91construct_rec_baseq_ext_strand(__pyx_self, __pyx_v_samfile, __pyx_v_fafile, __pyx_v_col, __pyx_v_one_based);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1718
 * 
 * 
 * cpdef object construct_rec_baseq_ext_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                                             PileupProxy col, bint one_based=False):
 * 
 */

static PyObject *__pyx_pf_10pysamstats_91construct_rec_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, struct __pyx_obj_5pysam_9csamtools_PileupProxy *__pyx_v_col, int __pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext_strand __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("construct_rec_baseq_ext_strand", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 1;
  __pyx_t_2.one_based = __pyx_v_one_based;
  __pyx_t_1 = __pyx_f_10pysamstats_construct_rec_baseq_ext_strand(__pyx_v_samfile, __pyx_v_fafile, __pyx_v_col, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("pysamstats.construct_rec_baseq_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_95generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_94stat_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_94stat_baseq_ext_strand = {__Pyx_NAMESTR("stat_baseq_ext_strand"), (PyCFunction)__pyx_pw_10pysamstats_94stat_baseq_ext_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_94stat_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_baseq_ext_strand (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__samfile,&__pyx_n_s__fafile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "pysamstats.pyx":1905
 * 
 * def stat_baseq_ext_strand(Samfile samfile, Fastafile fafile,
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    values[5] = __pyx_k_51;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        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__fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stat_baseq_ext_strand", 0, 2, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1904; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__chrom);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_baseq_ext_strand") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1904; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)values[1]);
    __pyx_v_chrom = values[2];
    __pyx_v_start = values[3];
    __pyx_v_end = values[4];
    __pyx_v_one_based = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_baseq_ext_strand", 0, 2, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1904; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_baseq_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_93stat_baseq_ext_strand(__pyx_self, __pyx_v_samfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1904
 * 
 * 
 * def stat_baseq_ext_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */

static PyObject *__pyx_pf_10pysamstats_93stat_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_baseq_ext_strand", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *)__pyx_ptype_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_fafile = __pyx_v_fafile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_95generator13, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_baseq_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_95generator13(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  struct __pyx_opt_args_10pysamstats_construct_rec_baseq_ext_strand __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L8_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 = 1904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1906
 * def stat_baseq_ext_strand(Samfile samfile, Fastafile fafile,
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_baseq_ext_strand(samfile, fafile, col, one_based)
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 1906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1906; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1907
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         yield construct_rec_baseq_ext_strand(samfile, fafile, col, one_based)
 * 
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1907; __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 = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1907; __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 = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1907; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":1908
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         yield construct_rec_baseq_ext_strand(samfile, fafile, col, one_based)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1908; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1908; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9.__pyx_n = 1;
    __pyx_t_9.one_based = __pyx_t_8;
    __pyx_t_3 = __pyx_f_10pysamstats_construct_rec_baseq_ext_strand(__pyx_cur_scope->__pyx_v_samfile, __pyx_cur_scope->__pyx_v_fafile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_2), 0, &__pyx_t_9); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1908; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L8_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1908; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_baseq_ext_strand", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_97write_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_97write_baseq_ext_strand = {__Pyx_NAMESTR("write_baseq_ext_strand"), (PyCFunction)__pyx_pw_10pysamstats_97write_baseq_ext_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_97write_baseq_ext_strand(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_baseq_ext_strand (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_baseq_ext_strand", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_96write_baseq_ext_strand(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1911
 * 
 * 
 * def write_baseq_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 */

static PyObject *__pyx_pf_10pysamstats_96write_baseq_ext_strand(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_baseq_ext_strand", 0);

  /* "pysamstats.pyx":1912
 * 
 * def write_baseq_ext_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'ref',             # <<<<<<<<<<<<<<
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 * #                  'reads_pp', 'reads_pp_fwd', 'reads_pp_rev',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_52));
  __pyx_v_fieldnames = __pyx_k_tuple_52;

  /* "pysamstats.pyx":1926
 *                   'rms_baseq_mismatches_pp', 'rms_baseq_mismatches_pp_fwd', 'rms_baseq_mismatches_pp_rev',
 *                   )
 *     write_stats(stat_baseq_ext_strand, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s_53); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1926; __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 = 1926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1926; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_baseq_ext_strand", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_100generator14(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_99stat_coverage_normed(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_99stat_coverage_normed = {__Pyx_NAMESTR("stat_coverage_normed"), (PyCFunction)__pyx_pw_10pysamstats_99stat_coverage_normed, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_99stat_coverage_normed(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_coverage_normed (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__samfile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "pysamstats.pyx":1937
 * 
 * 
 * def stat_coverage_normed(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 * 
 */
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = __pyx_k_54;
    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__chrom);
          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__one_based);
          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, "stat_coverage_normed") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __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_9csamtools_Samfile *)values[0]);
    __pyx_v_chrom = values[1];
    __pyx_v_start = values[2];
    __pyx_v_end = values[3];
    __pyx_v_one_based = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_normed", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_coverage_normed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_98stat_coverage_normed(__pyx_self, __pyx_v_samfile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_20stat_coverage_normed_2generator17(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysamstats.pyx":1941
 * 
 *     # first need to load the coverage data into an array, to calculate the median
 *     it = (col.n for col in samfile.pileup(reference=chrom, start=start, end=end))             # <<<<<<<<<<<<<<
 *     a = np.fromiter(it, dtype='u4')
 *     dp_mean = np.mean(a)
 */

static PyObject *__pyx_pf_10pysamstats_20stat_coverage_normed_genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *)__pyx_ptype_10pysamstats___pyx_scope_struct_15_genexpr->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_15_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_20stat_coverage_normed_2generator17, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_coverage_normed.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_20stat_coverage_normed_2generator17(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  __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 = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_samfile)) { __Pyx_RaiseClosureNameError("samfile"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_outer_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __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 = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_chrom)) { __Pyx_RaiseClosureNameError("chrom"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_outer_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_start)) { __Pyx_RaiseClosureNameError("start"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_outer_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_end)) { __Pyx_RaiseClosureNameError("end"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_outer_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if (PyList_CheckExact(__pyx_t_3) || PyTuple_CheckExact(__pyx_t_3)) {
    __pyx_t_2 = __pyx_t_3; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (!__pyx_t_5 && PyList_CheckExact(__pyx_t_2)) {
      if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_5 && PyTuple_CheckExact(__pyx_t_2)) {
      if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_3 = __pyx_t_5(__pyx_t_2);
      if (unlikely(!__pyx_t_3)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_3);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_3;
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_col, __pyx_n_s__n); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    __Pyx_XGIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_2;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_4;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_5;
    __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_2 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_2);
    __pyx_t_4 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_5 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  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;
}

/* "pysamstats.pyx":1937
 * 
 * 
 * def stat_coverage_normed(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 * 
 */

static PyObject *__pyx_pf_10pysamstats_98stat_coverage_normed(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_coverage_normed", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *)__pyx_ptype_10pysamstats___pyx_scope_struct_14_stat_coverage_normed->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_14_stat_coverage_normed, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_100generator14, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_coverage_normed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_100generator14(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  long __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  int __pyx_t_9;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L10_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 = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1938
 * 
 * def stat_coverage_normed(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 * 
 *     # first need to load the coverage data into an array, to calculate the median
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1941
 * 
 *     # first need to load the coverage data into an array, to calculate the median
 *     it = (col.n for col in samfile.pileup(reference=chrom, start=start, end=end))             # <<<<<<<<<<<<<<
 *     a = np.fromiter(it, dtype='u4')
 *     dp_mean = np.mean(a)
 */
  __pyx_t_3 = __pyx_pf_10pysamstats_20stat_coverage_normed_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_cur_scope->__pyx_v_it = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":1942
 *     # first need to load the coverage data into an array, to calculate the median
 *     it = (col.n for col in samfile.pileup(reference=chrom, start=start, end=end))
 *     a = np.fromiter(it, dtype='u4')             # <<<<<<<<<<<<<<
 *     dp_mean = np.mean(a)
 *     dp_median = np.median(a)
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__fromiter); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_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 = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_it);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_cur_scope->__pyx_v_it);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_it);
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_n_s__u4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_cur_scope->__pyx_v_a = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":1943
 *     it = (col.n for col in samfile.pileup(reference=chrom, start=start, end=end))
 *     a = np.fromiter(it, dtype='u4')
 *     dp_mean = np.mean(a)             # <<<<<<<<<<<<<<
 *     dp_median = np.median(a)
 *     dp_percentiles = [np.percentile(a, q) for q in range(101)]
 */
  __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__mean); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __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 = 1943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_a);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_cur_scope->__pyx_v_a);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_a);
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1943; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_cur_scope->__pyx_v_dp_mean = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":1944
 *     a = np.fromiter(it, dtype='u4')
 *     dp_mean = np.mean(a)
 *     dp_median = np.median(a)             # <<<<<<<<<<<<<<
 *     dp_percentiles = [np.percentile(a, q) for q in range(101)]
 * 
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__median); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __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 = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_a);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_cur_scope->__pyx_v_a);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_a);
  __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_dp_median = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":1945
 *     dp_mean = np.mean(a)
 *     dp_median = np.median(a)
 *     dp_percentiles = [np.percentile(a, q) for q in range(101)]             # <<<<<<<<<<<<<<
 * 
 *     # then iterate again to generate stats
 */
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  for (__pyx_t_6 = 0; __pyx_t_6 < 101; __pyx_t_6+=1) {
    __pyx_cur_scope->__pyx_v_q = __pyx_t_6;
    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__percentile); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_q); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_a);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_cur_scope->__pyx_v_a);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_a);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    if (unlikely(__Pyx_PyList_Append(__pyx_t_2, (PyObject*)__pyx_t_3))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_t_3 = ((PyObject *)__pyx_t_2);
  __Pyx_INCREF(__pyx_t_3);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_cur_scope->__pyx_v_dp_percentiles = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":1948
 * 
 *     # then iterate again to generate stats
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 *         chrom = samfile.getrname(col.tid)
 *         pos = col.pos + 1 if one_based else col.pos
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_7 = 0;
    __pyx_t_8 = NULL;
  } else {
    __pyx_t_7 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = Py_TYPE(__pyx_t_2)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (!__pyx_t_8 && PyList_CheckExact(__pyx_t_2)) {
      if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_8 && PyTuple_CheckExact(__pyx_t_2)) {
      if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_1 = __pyx_t_8(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1948; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "pysamstats.pyx":1949
 *     # then iterate again to generate stats
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 *         pos = col.pos + 1 if one_based else col.pos
 *         dp = col.n
 */
    __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__getrname); 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_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_col, __pyx_n_s__tid); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1949; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_chrom);
    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_chrom);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_v_chrom = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1950
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 *         chrom = samfile.getrname(col.tid)
 *         pos = col.pos + 1 if one_based else col.pos             # <<<<<<<<<<<<<<
 *         dp = col.n
 *         dp_normed_median = dp * 1. / dp_median
 */
    __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (__pyx_t_9) {
      __pyx_t_4 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_col, __pyx_n_s__pos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = PyNumber_Add(__pyx_t_4, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_3 = __pyx_t_1;
      __pyx_t_1 = 0;
    } else {
      __pyx_t_1 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_col, __pyx_n_s__pos); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1950; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1;
      __pyx_t_1 = 0;
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_pos);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_pos);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_v_pos = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1951
 *         chrom = samfile.getrname(col.tid)
 *         pos = col.pos + 1 if one_based else col.pos
 *         dp = col.n             # <<<<<<<<<<<<<<
 *         dp_normed_median = dp * 1. / dp_median
 *         dp_normed_mean = dp * 1. / dp_mean
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_col, __pyx_n_s__n); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1951; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dp);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_dp);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_v_dp = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1952
 *         pos = col.pos + 1 if one_based else col.pos
 *         dp = col.n
 *         dp_normed_median = dp * 1. / dp_median             # <<<<<<<<<<<<<<
 *         dp_normed_mean = dp * 1. / dp_mean
 *         dp_percentile = bisect_left(dp_percentiles, dp)
 */
    __pyx_t_3 = PyFloat_FromDouble(1.); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyNumber_Multiply(__pyx_cur_scope->__pyx_v_dp, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_cur_scope->__pyx_v_dp_median); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1952; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dp_normed_median);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_dp_normed_median);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_v_dp_normed_median = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1953
 *         dp = col.n
 *         dp_normed_median = dp * 1. / dp_median
 *         dp_normed_mean = dp * 1. / dp_mean             # <<<<<<<<<<<<<<
 *         dp_percentile = bisect_left(dp_percentiles, dp)
 *         yield {'chrom': chrom, 'pos': pos,
 */
    __pyx_t_3 = PyFloat_FromDouble(1.); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyNumber_Multiply(__pyx_cur_scope->__pyx_v_dp, __pyx_t_3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_cur_scope->__pyx_v_dp_mean); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dp_normed_mean);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_dp_normed_mean);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_v_dp_normed_mean = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1954
 *         dp_normed_median = dp * 1. / dp_median
 *         dp_normed_mean = dp * 1. / dp_mean
 *         dp_percentile = bisect_left(dp_percentiles, dp)             # <<<<<<<<<<<<<<
 *         yield {'chrom': chrom, 'pos': pos,
 *                'reads_all': col.n,
 */
    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__bisect_left); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_dp_percentiles));
    PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_cur_scope->__pyx_v_dp_percentiles));
    __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_dp_percentiles));
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_dp);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_cur_scope->__pyx_v_dp);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_dp);
    __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dp_percentile);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_dp_percentile);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_cur_scope->__pyx_v_dp_percentile = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":1955
 *         dp_normed_mean = dp * 1. / dp_mean
 *         dp_percentile = bisect_left(dp_percentiles, dp)
 *         yield {'chrom': chrom, 'pos': pos,             # <<<<<<<<<<<<<<
 *                'reads_all': col.n,
 *                'dp_normed_median': dp_normed_median,
 */
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__pos), __pyx_cur_scope->__pyx_v_pos) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":1956
 *         dp_percentile = bisect_left(dp_percentiles, dp)
 *         yield {'chrom': chrom, 'pos': pos,
 *                'reads_all': col.n,             # <<<<<<<<<<<<<<
 *                'dp_normed_median': dp_normed_median,
 *                'dp_normed_mean': dp_normed_mean,
 */
    __pyx_t_1 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_col, __pyx_n_s__n); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1956; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__reads_all), __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysamstats.pyx":1957
 *         yield {'chrom': chrom, 'pos': pos,
 *                'reads_all': col.n,
 *                'dp_normed_median': dp_normed_median,             # <<<<<<<<<<<<<<
 *                'dp_normed_mean': dp_normed_mean,
 *                'dp_percentile': dp_percentile}
 */
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dp_normed_median), __pyx_cur_scope->__pyx_v_dp_normed_median) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":1958
 *                'reads_all': col.n,
 *                'dp_normed_median': dp_normed_median,
 *                'dp_normed_mean': dp_normed_mean,             # <<<<<<<<<<<<<<
 *                'dp_percentile': dp_percentile}
 * 
 */
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dp_normed_mean), __pyx_cur_scope->__pyx_v_dp_normed_mean) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":1959
 *                'dp_normed_median': dp_normed_median,
 *                'dp_normed_mean': dp_normed_mean,
 *                'dp_percentile': dp_percentile}             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__dp_percentile), __pyx_cur_scope->__pyx_v_dp_percentile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_r = ((PyObject *)__pyx_t_4);
    __pyx_t_4 = 0;
    __Pyx_XGIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_2;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_7;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_8;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L10_resume_from_yield:;
    __pyx_t_2 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_2);
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_8 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  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_4);
  __Pyx_AddTraceback("stat_coverage_normed", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_102write_coverage_normed(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_102write_coverage_normed = {__Pyx_NAMESTR("write_coverage_normed"), (PyCFunction)__pyx_pw_10pysamstats_102write_coverage_normed, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_102write_coverage_normed(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_coverage_normed (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_coverage_normed", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_101write_coverage_normed(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1962
 * 
 * 
 * def write_coverage_normed(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'reads_all',
 *                   'dp_normed_median',
 */

static PyObject *__pyx_pf_10pysamstats_101write_coverage_normed(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_coverage_normed", 0);

  /* "pysamstats.pyx":1963
 * 
 * def write_coverage_normed(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'reads_all',             # <<<<<<<<<<<<<<
 *                   'dp_normed_median',
 *                   'dp_normed_mean',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_55));
  __pyx_v_fieldnames = __pyx_k_tuple_55;

  /* "pysamstats.pyx":1967
 *                   'dp_normed_mean',
 *                   'dp_percentile')
 *     write_stats(stat_coverage_normed, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s_56); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1967; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_coverage_normed", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_105generator15(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_104stat_coverage_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_104stat_coverage_gc = {__Pyx_NAMESTR("stat_coverage_gc"), (PyCFunction)__pyx_pw_10pysamstats_104stat_coverage_gc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_104stat_coverage_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  PyObject *__pyx_v_gc_window_length = 0;
  PyObject *__pyx_v_gc_window_offset = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_coverage_gc (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__samfile,&__pyx_n_s__fafile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,&__pyx_n_s__gc_window_length,&__pyx_n_s__gc_window_offset,0};
    PyObject* values[8] = {0,0,0,0,0,0,0,0};

    /* "pysamstats.pyx":1979
 * 
 * def stat_coverage_gc(Samfile samfile, Fastafile fafile,
 *                      chrom=None, start=None, end=None, one_based=False,             # <<<<<<<<<<<<<<
 *                      gc_window_length=300, gc_window_offset=150, **kwargs):
 *     cdef Py_ssize_t i # loop index
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    values[5] = __pyx_k_57;
    values[6] = ((PyObject *)__pyx_int_300);
    values[7] = ((PyObject *)__pyx_int_150);
    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 (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__fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stat_coverage_gc", 0, 2, 8, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__chrom);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gc_window_length);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__gc_window_offset);
          if (value) { values[7] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_coverage_gc") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __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);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)values[1]);
    __pyx_v_chrom = values[2];
    __pyx_v_start = values[3];
    __pyx_v_end = values[4];
    __pyx_v_one_based = values[5];
    __pyx_v_gc_window_length = values[6];
    __pyx_v_gc_window_offset = values[7];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_gc", 0, 2, 8, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_coverage_gc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_103stat_coverage_gc(__pyx_self, __pyx_v_samfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_gc_window_length, __pyx_v_gc_window_offset, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":1978
 * 
 * 
 * def stat_coverage_gc(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                      chrom=None, start=None, end=None, one_based=False,
 *                      gc_window_length=300, gc_window_offset=150, **kwargs):
 */

static PyObject *__pyx_pf_10pysamstats_103stat_coverage_gc(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_gc_window_length, PyObject *__pyx_v_gc_window_offset, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_coverage_gc", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *)__pyx_ptype_10pysamstats___pyx_scope_struct_16_stat_coverage_gc->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_16_stat_coverage_gc, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_fafile = __pyx_v_fafile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_gc_window_length = __pyx_v_gc_window_length;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_gc_window_length);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_gc_window_length);
  __pyx_cur_scope->__pyx_v_gc_window_offset = __pyx_v_gc_window_offset;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_gc_window_offset);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_gc_window_offset);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_105generator15, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_coverage_gc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_105generator15(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  Py_ssize_t __pyx_t_9;
  char *__pyx_t_10;
  long __pyx_t_11;
  int __pyx_t_12;
  int __pyx_t_13;
  struct __pyx_opt_args_10pysamstats_construct_rec_coverage __pyx_t_14;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L13_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 = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1985
 *     cdef int gc_count
 * 
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1985; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1986
 * 
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):             # <<<<<<<<<<<<<<
 * 
 *         chrom = samfile.getrname(col.tid)
 */
  __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__pileup); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__reference), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_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 = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_7 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1986; __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 = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_7 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_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 = 1986; __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 = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_col);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_col = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":1988
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 * 
 *         chrom = samfile.getrname(col.tid)             # <<<<<<<<<<<<<<
 * 
 *         if col.pos <= gc_window_offset:
 */
    __pyx_t_2 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_samfile), __pyx_n_s__getrname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_col, __pyx_n_s__tid); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1988; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_chrom);
    __Pyx_DECREF(__pyx_cur_scope->__pyx_v_chrom);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_v_chrom = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1990
 *         chrom = samfile.getrname(col.tid)
 * 
 *         if col.pos <= gc_window_offset:             # <<<<<<<<<<<<<<
 *             continue # until we get a bit further into the chromosome
 * 
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_col, __pyx_n_s__pos); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_cur_scope->__pyx_v_gc_window_offset, Py_LE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1990; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_8) {

      /* "pysamstats.pyx":1991
 * 
 *         if col.pos <= gc_window_offset:
 *             continue # until we get a bit further into the chromosome             # <<<<<<<<<<<<<<
 * 
 *         ref_window_start = col.pos - gc_window_offset
 */
      goto __pyx_L6_continue;
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "pysamstats.pyx":1993
 *             continue # until we get a bit further into the chromosome
 * 
 *         ref_window_start = col.pos - gc_window_offset             # <<<<<<<<<<<<<<
 *         ref_window_end = ref_window_start + gc_window_length
 *         ref_window = fafile.fetch(chrom, ref_window_start, ref_window_end)
 */
    __pyx_t_4 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_col, __pyx_n_s__pos); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_cur_scope->__pyx_v_gc_window_offset); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1993; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_ref_window_start);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_ref_window_start);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_v_ref_window_start = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1994
 * 
 *         ref_window_start = col.pos - gc_window_offset
 *         ref_window_end = ref_window_start + gc_window_length             # <<<<<<<<<<<<<<
 *         ref_window = fafile.fetch(chrom, ref_window_start, ref_window_end)
 * 
 */
    __pyx_t_3 = PyNumber_Add(__pyx_cur_scope->__pyx_v_ref_window_start, __pyx_cur_scope->__pyx_v_gc_window_length); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1994; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_ref_window_end);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_ref_window_end);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_v_ref_window_end = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "pysamstats.pyx":1995
 *         ref_window_start = col.pos - gc_window_offset
 *         ref_window_end = ref_window_start + gc_window_length
 *         ref_window = fafile.fetch(chrom, ref_window_start, ref_window_end)             # <<<<<<<<<<<<<<
 * 
 *         if len(ref_window) == 0:
 */
    __pyx_t_3 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_fafile), __pyx_n_s__fetch); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_cur_scope->__pyx_v_chrom);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_ref_window_start);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_cur_scope->__pyx_v_ref_window_start);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_ref_window_start);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_ref_window_end);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_cur_scope->__pyx_v_ref_window_end);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_ref_window_end);
    __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1995; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_ref_window);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_ref_window);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_ref_window = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":1997
 *         ref_window = fafile.fetch(chrom, ref_window_start, ref_window_end)
 * 
 *         if len(ref_window) == 0:             # <<<<<<<<<<<<<<
 *             break # because we've hit the end of the chromosome
 * 
 */
    __pyx_t_9 = PyObject_Length(__pyx_cur_scope->__pyx_v_ref_window); if (unlikely(__pyx_t_9 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1997; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_8 = (__pyx_t_9 == 0);
    if (__pyx_t_8) {

      /* "pysamstats.pyx":1998
 * 
 *         if len(ref_window) == 0:
 *             break # because we've hit the end of the chromosome             # <<<<<<<<<<<<<<
 * 
 *         seq = ref_window
 */
      goto __pyx_L7_break;
      goto __pyx_L9;
    }
    __pyx_L9:;

    /* "pysamstats.pyx":2000
 *             break # because we've hit the end of the chromosome
 * 
 *         seq = ref_window             # <<<<<<<<<<<<<<
 *         gc_count = 0
 *         for i in range(gc_window_length):
 */
    __pyx_t_10 = PyBytes_AsString(__pyx_cur_scope->__pyx_v_ref_window); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2000; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_cur_scope->__pyx_v_seq = __pyx_t_10;

    /* "pysamstats.pyx":2001
 * 
 *         seq = ref_window
 *         gc_count = 0             # <<<<<<<<<<<<<<
 *         for i in range(gc_window_length):
 *             b = seq[i]
 */
    __pyx_cur_scope->__pyx_v_gc_count = 0;

    /* "pysamstats.pyx":2002
 *         seq = ref_window
 *         gc_count = 0
 *         for i in range(gc_window_length):             # <<<<<<<<<<<<<<
 *             b = seq[i]
 *             if b == 'g' or b == 'c':
 */
    __pyx_t_11 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_gc_window_length); if (unlikely((__pyx_t_11 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_11; __pyx_t_9+=1) {
      __pyx_cur_scope->__pyx_v_i = __pyx_t_9;

      /* "pysamstats.pyx":2003
 *         gc_count = 0
 *         for i in range(gc_window_length):
 *             b = seq[i]             # <<<<<<<<<<<<<<
 *             if b == 'g' or b == 'c':
 *                 gc_count += 1
 */
      __pyx_cur_scope->__pyx_v_b = (__pyx_cur_scope->__pyx_v_seq[__pyx_cur_scope->__pyx_v_i]);

      /* "pysamstats.pyx":2004
 *         for i in range(gc_window_length):
 *             b = seq[i]
 *             if b == 'g' or b == 'c':             # <<<<<<<<<<<<<<
 *                 gc_count += 1
 * 
 */
      __pyx_t_8 = (__pyx_cur_scope->__pyx_v_b == 'g');
      if (!__pyx_t_8) {
        __pyx_t_12 = (__pyx_cur_scope->__pyx_v_b == 'c');
        __pyx_t_13 = __pyx_t_12;
      } else {
        __pyx_t_13 = __pyx_t_8;
      }
      if (__pyx_t_13) {

        /* "pysamstats.pyx":2005
 *             b = seq[i]
 *             if b == 'g' or b == 'c':
 *                 gc_count += 1             # <<<<<<<<<<<<<<
 * 
 *         gc_percent = int(round(gc_count * 100. / gc_window_length))
 */
        __pyx_cur_scope->__pyx_v_gc_count = (__pyx_cur_scope->__pyx_v_gc_count + 1);
        goto __pyx_L12;
      }
      __pyx_L12:;
    }

    /* "pysamstats.pyx":2007
 *                 gc_count += 1
 * 
 *         gc_percent = int(round(gc_count * 100. / gc_window_length))             # <<<<<<<<<<<<<<
 * 
 *         rec = construct_rec_coverage(samfile, col, one_based)
 */
    __pyx_t_2 = PyFloat_FromDouble((__pyx_cur_scope->__pyx_v_gc_count * 100.)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_cur_scope->__pyx_v_gc_window_length); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_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 = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_gc_percent);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_gc_percent);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_cur_scope->__pyx_v_gc_percent = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":2009
 *         gc_percent = int(round(gc_count * 100. / gc_window_length))
 * 
 *         rec = construct_rec_coverage(samfile, col, one_based)             # <<<<<<<<<<<<<<
 *         rec['gc'] = gc_percent
 *         yield rec
 */
    if (!(likely(((__pyx_cur_scope->__pyx_v_col) == Py_None) || likely(__Pyx_TypeTest(__pyx_cur_scope->__pyx_v_col, __pyx_ptype_5pysam_9csamtools_PileupProxy))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = __pyx_cur_scope->__pyx_v_col;
    __Pyx_INCREF(__pyx_t_4);
    __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_one_based); if (unlikely((__pyx_t_13 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_14.__pyx_n = 1;
    __pyx_t_14.one_based = __pyx_t_13;
    __pyx_t_2 = __pyx_f_10pysamstats_construct_rec_coverage(__pyx_cur_scope->__pyx_v_samfile, ((struct __pyx_obj_5pysam_9csamtools_PileupProxy *)__pyx_t_4), 0, &__pyx_t_14); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2009; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_rec);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_rec);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_rec = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":2010
 * 
 *         rec = construct_rec_coverage(samfile, col, one_based)
 *         rec['gc'] = gc_percent             # <<<<<<<<<<<<<<
 *         yield rec
 * 
 */
    if (PyObject_SetItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__gc), __pyx_cur_scope->__pyx_v_gc_percent) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2010; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":2011
 *         rec = construct_rec_coverage(samfile, col, one_based)
 *         rec['gc'] = gc_percent
 *         yield rec             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_rec);
    __pyx_r = __pyx_cur_scope->__pyx_v_rec;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_6;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_7;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L13_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_6 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_7 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L6_continue:;
  }
  __pyx_L7_break:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  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_4);
  __Pyx_AddTraceback("stat_coverage_gc", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_107write_coverage_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_107write_coverage_gc = {__Pyx_NAMESTR("write_coverage_gc"), (PyCFunction)__pyx_pw_10pysamstats_107write_coverage_gc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_107write_coverage_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_coverage_gc (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_coverage_gc", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_106write_coverage_gc(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2014
 * 
 * 
 * def write_coverage_gc(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'gc', 'reads_all', 'reads_pp')
 *     write_stats(stat_coverage_gc, fieldnames, *args, **kwargs)
 */

static PyObject *__pyx_pf_10pysamstats_106write_coverage_gc(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_coverage_gc", 0);

  /* "pysamstats.pyx":2015
 * 
 * def write_coverage_gc(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'gc', 'reads_all', 'reads_pp')             # <<<<<<<<<<<<<<
 *     write_stats(stat_coverage_gc, fieldnames, *args, **kwargs)
 * 
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_58));
  __pyx_v_fieldnames = __pyx_k_tuple_58;

  /* "pysamstats.pyx":2016
 * def write_coverage_gc(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'gc', 'reads_all', 'reads_pp')
 *     write_stats(stat_coverage_gc, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_coverage_gc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2016; __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 = 2016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2016; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_coverage_gc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_110generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_109stat_coverage_normed_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_109stat_coverage_normed_gc = {__Pyx_NAMESTR("stat_coverage_normed_gc"), (PyCFunction)__pyx_pw_10pysamstats_109stat_coverage_normed_gc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_109stat_coverage_normed_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile = 0;
  struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("stat_coverage_normed_gc (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__samfile,&__pyx_n_s__fafile,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,0};
    PyObject* values[6] = {0,0,0,0,0,0};

    /* "pysamstats.pyx":2024
 * 
 * 
 * def stat_coverage_normed_gc(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 * 
 */
    values[2] = ((PyObject *)Py_None);
    values[3] = ((PyObject *)Py_None);
    values[4] = ((PyObject *)Py_None);
    values[5] = __pyx_k_59;
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        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__fafile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("stat_coverage_normed_gc", 0, 2, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__chrom);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "stat_coverage_normed_gc") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)values[0]);
    __pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)values[1]);
    __pyx_v_chrom = values[2];
    __pyx_v_start = values[3];
    __pyx_v_end = values[4];
    __pyx_v_one_based = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("stat_coverage_normed_gc", 0, 2, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_CLEAR(__pyx_v_kwargs);
  __Pyx_AddTraceback("pysamstats.stat_coverage_normed_gc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_samfile), __pyx_ptype_5pysam_9csamtools_Samfile, 1, "samfile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fafile), __pyx_ptype_5pysam_9csamtools_Fastafile, 1, "fafile", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_10pysamstats_108stat_coverage_normed_gc(__pyx_self, __pyx_v_samfile, __pyx_v_fafile, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_kwargs);
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
static PyObject *__pyx_gb_10pysamstats_23stat_coverage_normed_gc_2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "pysamstats.pyx":2029
 *     # first need to load the coverage data into an array, to calculate the median
 *     recs = stat_coverage_gc(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based)
 *     it = ((rec['reads_all'], rec['gc']) for rec in recs)             # <<<<<<<<<<<<<<
 *     a = np.fromiter(it, dtype=[('dp', 'u4'), ('gc', 'u1')]).view(np.recarray)
 *     dp_mean = np.mean(a.dp)
 */

static PyObject *__pyx_pf_10pysamstats_23stat_coverage_normed_gc_genexpr(PyObject *__pyx_self) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("genexpr", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *)__pyx_ptype_10pysamstats___pyx_scope_struct_18_genexpr->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_18_genexpr, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *) __pyx_self;
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_23stat_coverage_normed_gc_2generator18, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_coverage_normed_gc.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_23stat_coverage_normed_gc_2generator18(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *)__pyx_generator->closure);
  PyObject *__pyx_r = NULL;
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *(*__pyx_t_3)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  __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 = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_recs)) { __Pyx_RaiseClosureNameError("recs"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
  if (PyList_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_recs) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_recs)) {
    __pyx_t_1 = __pyx_cur_scope->__pyx_outer_scope->__pyx_v_recs; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_recs); 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_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext;
  }
  for (;;) {
    if (!__pyx_t_3 && PyList_CheckExact(__pyx_t_1)) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_3 && PyTuple_CheckExact(__pyx_t_1)) {
      if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_rec);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_rec);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_cur_scope->__pyx_v_rec = __pyx_t_4;
    __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__reads_all)); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__gc)); if (!__pyx_t_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __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 = 2029; __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_r = ((PyObject *)__pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_XGIVEREF(__pyx_t_1);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_3;
    __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_2 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_3 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  PyErr_SetNone(PyExc_StopIteration);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __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;
}

/* "pysamstats.pyx":2024
 * 
 * 
 * def stat_coverage_normed_gc(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 * 
 */

static PyObject *__pyx_pf_10pysamstats_108stat_coverage_normed_gc(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_5pysam_9csamtools_Samfile *__pyx_v_samfile, struct __pyx_obj_5pysam_9csamtools_Fastafile *__pyx_v_fafile, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *__pyx_cur_scope;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("stat_coverage_normed_gc", 0);
  __pyx_cur_scope = (struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *)__pyx_ptype_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc->tp_new(__pyx_ptype_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc, __pyx_empty_tuple, NULL);
  if (unlikely(!__pyx_cur_scope)) {
    __Pyx_RefNannyFinishContext();
    return NULL;
  }
  __Pyx_GOTREF(__pyx_cur_scope);
  __pyx_cur_scope->__pyx_v_samfile = __pyx_v_samfile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_samfile);
  __pyx_cur_scope->__pyx_v_fafile = __pyx_v_fafile;
  __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_fafile);
  __pyx_cur_scope->__pyx_v_chrom = __pyx_v_chrom;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_chrom);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_chrom);
  __pyx_cur_scope->__pyx_v_start = __pyx_v_start;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __pyx_cur_scope->__pyx_v_end = __pyx_v_end;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __pyx_cur_scope->__pyx_v_one_based = __pyx_v_one_based;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_cur_scope->__pyx_v_kwargs = __pyx_v_kwargs;
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_kwargs);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_kwargs);
  {
    __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_10pysamstats_110generator16, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_cur_scope);
    __Pyx_RefNannyFinishContext();
    return (PyObject *) gen;
  }

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_AddTraceback("pysamstats.stat_coverage_normed_gc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_DECREF(((PyObject *)__pyx_cur_scope));
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_gb_10pysamstats_110generator16(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
  struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *__pyx_cur_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *)__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 = NULL;
  PyObject *(*__pyx_t_5)(PyObject *);
  long __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  PyObject *(*__pyx_t_9)(PyObject *);
  int __pyx_t_10;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("None", 0);
  switch (__pyx_generator->resume_label) {
    case 0: goto __pyx_L3_first_run;
    case 1: goto __pyx_L15_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 = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2025
 * 
 * def stat_coverage_normed_gc(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)             # <<<<<<<<<<<<<<
 * 
 *     # first need to load the coverage data into an array, to calculate the median
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__normalise_coords); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_one_based);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_cur_scope->__pyx_v_one_based);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_one_based);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #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 = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    #if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2025; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_L5_unpacking_done:;
  }
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_start);
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_start = __pyx_t_2;
  __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_end);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_cur_scope->__pyx_v_end = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":2028
 * 
 *     # first need to load the coverage data into an array, to calculate the median
 *     recs = stat_coverage_gc(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based)             # <<<<<<<<<<<<<<
 *     it = ((rec['reads_all'], rec['gc']) for rec in recs)
 *     a = np.fromiter(it, dtype=[('dp', 'u4'), ('gc', 'u1')]).view(np.recarray)
 */
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_coverage_gc); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_cur_scope->__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_samfile));
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fafile));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_cur_scope->__pyx_v_fafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_fafile));
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__chrom), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__one_based), __pyx_cur_scope->__pyx_v_one_based) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2028; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_cur_scope->__pyx_v_recs = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":2029
 *     # first need to load the coverage data into an array, to calculate the median
 *     recs = stat_coverage_gc(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based)
 *     it = ((rec['reads_all'], rec['gc']) for rec in recs)             # <<<<<<<<<<<<<<
 *     a = np.fromiter(it, dtype=[('dp', 'u4'), ('gc', 'u1')]).view(np.recarray)
 *     dp_mean = np.mean(a.dp)
 */
  __pyx_t_4 = __pyx_pf_10pysamstats_23stat_coverage_normed_gc_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_cur_scope->__pyx_v_it = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":2030
 *     recs = stat_coverage_gc(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based)
 *     it = ((rec['reads_all'], rec['gc']) for rec in recs)
 *     a = np.fromiter(it, dtype=[('dp', 'u4'), ('gc', 'u1')]).view(np.recarray)             # <<<<<<<<<<<<<<
 *     dp_mean = np.mean(a.dp)
 *     dp_median = np.median(a.dp)
 */
  __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__fromiter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __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 = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_cur_scope->__pyx_v_it);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_cur_scope->__pyx_v_it);
  __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_it);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_1));
  __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_60));
  PyList_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_k_tuple_60));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60));
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_61));
  PyList_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_k_tuple_61));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_61));
  if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__dtype), ((PyObject *)__pyx_t_3)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_t_3 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__view); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__recarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_cur_scope->__pyx_v_a = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":2031
 *     it = ((rec['reads_all'], rec['gc']) for rec in recs)
 *     a = np.fromiter(it, dtype=[('dp', 'u4'), ('gc', 'u1')]).view(np.recarray)
 *     dp_mean = np.mean(a.dp)             # <<<<<<<<<<<<<<
 *     dp_median = np.median(a.dp)
 *     dp_percentiles = [np.percentile(a.dp, q) for q in range(101)]
 */
  __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__mean); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_a, __pyx_n_s__dp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2031; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_cur_scope->__pyx_v_dp_mean = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":2032
 *     a = np.fromiter(it, dtype=[('dp', 'u4'), ('gc', 'u1')]).view(np.recarray)
 *     dp_mean = np.mean(a.dp)
 *     dp_median = np.median(a.dp)             # <<<<<<<<<<<<<<
 *     dp_percentiles = [np.percentile(a.dp, q) for q in range(101)]
 *     dp_mean_bygc = dict()
 */
  __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_4, __pyx_n_s__median); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_a, __pyx_n_s__dp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __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 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2032; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_cur_scope->__pyx_v_dp_median = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":2033
 *     dp_mean = np.mean(a.dp)
 *     dp_median = np.median(a.dp)
 *     dp_percentiles = [np.percentile(a.dp, q) for q in range(101)]             # <<<<<<<<<<<<<<
 *     dp_mean_bygc = dict()
 *     dp_median_bygc = dict()
 */
  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  for (__pyx_t_6 = 0; __pyx_t_6 < 101; __pyx_t_6+=1) {
    __pyx_cur_scope->__pyx_v_q = __pyx_t_6;
    __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__percentile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_a, __pyx_n_s__dp); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_q); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __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_2);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
    if (unlikely(__Pyx_PyList_Append(__pyx_t_4, (PyObject*)__pyx_t_2))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2033; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __pyx_t_2 = ((PyObject *)__pyx_t_4);
  __Pyx_INCREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_v_dp_percentiles = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":2034
 *     dp_median = np.median(a.dp)
 *     dp_percentiles = [np.percentile(a.dp, q) for q in range(101)]
 *     dp_mean_bygc = dict()             # <<<<<<<<<<<<<<
 *     dp_median_bygc = dict()
 *     dp_percentiles_bygc = dict()
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2034; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  __pyx_cur_scope->__pyx_v_dp_mean_bygc = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":2035
 *     dp_percentiles = [np.percentile(a.dp, q) for q in range(101)]
 *     dp_mean_bygc = dict()
 *     dp_median_bygc = dict()             # <<<<<<<<<<<<<<
 *     dp_percentiles_bygc = dict()
 *     for gc in range(101):
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2035; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  __pyx_cur_scope->__pyx_v_dp_median_bygc = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":2036
 *     dp_mean_bygc = dict()
 *     dp_median_bygc = dict()
 *     dp_percentiles_bygc = dict()             # <<<<<<<<<<<<<<
 *     for gc in range(101):
 *         flt = a.gc == gc
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2036; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __Pyx_GIVEREF(((PyObject *)__pyx_t_2));
  __pyx_cur_scope->__pyx_v_dp_percentiles_bygc = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":2037
 *     dp_median_bygc = dict()
 *     dp_percentiles_bygc = dict()
 *     for gc in range(101):             # <<<<<<<<<<<<<<
 *         flt = a.gc == gc
 *         if np.count_nonzero(flt) > 0:
 */
  __pyx_t_2 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_k_tuple_62), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) {
    __pyx_t_4 = __pyx_t_2; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0;
    __pyx_t_9 = NULL;
  } else {
    __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  for (;;) {
    if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) {
      if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) {
      if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_2 = __pyx_t_9(__pyx_t_4);
      if (unlikely(!__pyx_t_2)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_gc);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_gc);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_gc = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":2038
 *     dp_percentiles_bygc = dict()
 *     for gc in range(101):
 *         flt = a.gc == gc             # <<<<<<<<<<<<<<
 *         if np.count_nonzero(flt) > 0:
 *             b = a[flt].dp
 */
    __pyx_t_2 = PyObject_GetAttr(__pyx_cur_scope->__pyx_v_a, __pyx_n_s__gc); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = PyObject_RichCompare(__pyx_t_2, __pyx_cur_scope->__pyx_v_gc, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_flt);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_flt);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_cur_scope->__pyx_v_flt = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "pysamstats.pyx":2039
 *     for gc in range(101):
 *         flt = a.gc == gc
 *         if np.count_nonzero(flt) > 0:             # <<<<<<<<<<<<<<
 *             b = a[flt].dp
 *             dp_mean_bygc[gc] = np.mean(b)
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__count_nonzero); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_flt);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_cur_scope->__pyx_v_flt);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_flt);
    __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_7), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_RichCompare(__pyx_t_1, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__pyx_t_10) {

      /* "pysamstats.pyx":2040
 *         flt = a.gc == gc
 *         if np.count_nonzero(flt) > 0:
 *             b = a[flt].dp             # <<<<<<<<<<<<<<
 *             dp_mean_bygc[gc] = np.mean(b)
 *             dp_median_bygc[gc] = np.median(b)
 */
      __pyx_t_7 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_a, __pyx_cur_scope->__pyx_v_flt); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_1 = PyObject_GetAttr(__pyx_t_7, __pyx_n_s__dp); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2040; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_b);
      __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_b);
      __Pyx_GIVEREF(__pyx_t_1);
      __pyx_cur_scope->__pyx_v_b = __pyx_t_1;
      __pyx_t_1 = 0;

      /* "pysamstats.pyx":2041
 *         if np.count_nonzero(flt) > 0:
 *             b = a[flt].dp
 *             dp_mean_bygc[gc] = np.mean(b)             # <<<<<<<<<<<<<<
 *             dp_median_bygc[gc] = np.median(b)
 *             dp_percentiles_bygc[gc] = [np.percentile(b, q) for q in range(101)]
 */
      __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__mean); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __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 = 2041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_b);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_cur_scope->__pyx_v_b);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_b);
      __pyx_t_2 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
      if (PyDict_SetItem(((PyObject *)__pyx_cur_scope->__pyx_v_dp_mean_bygc), __pyx_cur_scope->__pyx_v_gc, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2041; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pysamstats.pyx":2042
 *             b = a[flt].dp
 *             dp_mean_bygc[gc] = np.mean(b)
 *             dp_median_bygc[gc] = np.median(b)             # <<<<<<<<<<<<<<
 *             dp_percentiles_bygc[gc] = [np.percentile(b, q) for q in range(101)]
 * 
 */
      __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__median); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2042; __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 = 2042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_cur_scope->__pyx_v_b);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_b);
      __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_b);
      __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
      if (PyDict_SetItem(((PyObject *)__pyx_cur_scope->__pyx_v_dp_median_bygc), __pyx_cur_scope->__pyx_v_gc, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2042; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "pysamstats.pyx":2043
 *             dp_mean_bygc[gc] = np.mean(b)
 *             dp_median_bygc[gc] = np.median(b)
 *             dp_percentiles_bygc[gc] = [np.percentile(b, q) for q in range(101)]             # <<<<<<<<<<<<<<
 * 
 *     # second pass
 */
      __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      for (__pyx_t_6 = 0; __pyx_t_6 < 101; __pyx_t_6+=1) {
        __pyx_cur_scope->__pyx_v_q = __pyx_t_6;
        __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__percentile); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyInt_FromLong(__pyx_cur_scope->__pyx_v_q); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __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 = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_cur_scope->__pyx_v_b);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_cur_scope->__pyx_v_b);
        __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_b);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __pyx_t_2 = 0;
        __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
        if (unlikely(__Pyx_PyList_Append(__pyx_t_7, (PyObject*)__pyx_t_2))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __pyx_t_2 = ((PyObject *)__pyx_t_7);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
      if (PyDict_SetItem(((PyObject *)__pyx_cur_scope->__pyx_v_dp_percentiles_bygc), __pyx_cur_scope->__pyx_v_gc, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2043; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      goto __pyx_L10;
    }
    __pyx_L10:;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "pysamstats.pyx":2046
 * 
 *     # second pass
 *     recs = stat_coverage_gc(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based)             # <<<<<<<<<<<<<<
 *     for rec in recs:
 *         dp = rec['reads_all']
 */
  __pyx_t_4 = __Pyx_GetName(__pyx_m, __pyx_n_s__stat_coverage_gc); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_samfile));
  PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_cur_scope->__pyx_v_samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_samfile));
  __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fafile));
  PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_cur_scope->__pyx_v_fafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_fafile));
  __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_7));
  if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__chrom), __pyx_cur_scope->__pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__start), __pyx_cur_scope->__pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__end), __pyx_cur_scope->__pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_7, ((PyObject *)__pyx_n_s__one_based), __pyx_cur_scope->__pyx_v_one_based) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_7)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2046; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_7)); __pyx_t_7 = 0;
  __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_recs);
  __Pyx_DECREF(__pyx_cur_scope->__pyx_v_recs);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_cur_scope->__pyx_v_recs = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "pysamstats.pyx":2047
 *     # second pass
 *     recs = stat_coverage_gc(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based)
 *     for rec in recs:             # <<<<<<<<<<<<<<
 *         dp = rec['reads_all']
 *         gc = rec['gc']
 */
  if (PyList_CheckExact(__pyx_cur_scope->__pyx_v_recs) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_recs)) {
    __pyx_t_3 = __pyx_cur_scope->__pyx_v_recs; __Pyx_INCREF(__pyx_t_3); __pyx_t_8 = 0;
    __pyx_t_9 = NULL;
  } else {
    __pyx_t_8 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_recs); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext;
  }
  for (;;) {
    if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_3)) {
      if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_3)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_7 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_3)) {
      if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #else
      __pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else {
      __pyx_t_7 = __pyx_t_9(__pyx_t_3);
      if (unlikely(!__pyx_t_7)) {
        if (PyErr_Occurred()) {
          if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2047; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_rec);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_rec);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_cur_scope->__pyx_v_rec = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "pysamstats.pyx":2048
 *     recs = stat_coverage_gc(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based)
 *     for rec in recs:
 *         dp = rec['reads_all']             # <<<<<<<<<<<<<<
 *         gc = rec['gc']
 *         dp_normed_median = dp * 1. / dp_median
 */
    __pyx_t_7 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__reads_all)); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2048; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dp);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_dp);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_cur_scope->__pyx_v_dp = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "pysamstats.pyx":2049
 *     for rec in recs:
 *         dp = rec['reads_all']
 *         gc = rec['gc']             # <<<<<<<<<<<<<<
 *         dp_normed_median = dp * 1. / dp_median
 *         dp_normed_mean = dp * 1. / dp_mean
 */
    __pyx_t_7 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__gc)); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2049; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_gc);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_gc);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_cur_scope->__pyx_v_gc = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "pysamstats.pyx":2050
 *         dp = rec['reads_all']
 *         gc = rec['gc']
 *         dp_normed_median = dp * 1. / dp_median             # <<<<<<<<<<<<<<
 *         dp_normed_mean = dp * 1. / dp_mean
 *         dp_percentile = bisect_left(dp_percentiles, dp)
 */
    __pyx_t_7 = PyFloat_FromDouble(1.); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = PyNumber_Multiply(__pyx_cur_scope->__pyx_v_dp, __pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_cur_scope->__pyx_v_dp_median); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2050; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dp_normed_median);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_dp_normed_median);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_cur_scope->__pyx_v_dp_normed_median = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "pysamstats.pyx":2051
 *         gc = rec['gc']
 *         dp_normed_median = dp * 1. / dp_median
 *         dp_normed_mean = dp * 1. / dp_mean             # <<<<<<<<<<<<<<
 *         dp_percentile = bisect_left(dp_percentiles, dp)
 *         dp_normed_median_bygc = dp * 1. / dp_median_bygc[gc]
 */
    __pyx_t_7 = PyFloat_FromDouble(1.); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = PyNumber_Multiply(__pyx_cur_scope->__pyx_v_dp, __pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_cur_scope->__pyx_v_dp_mean); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2051; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dp_normed_mean);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_dp_normed_mean);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_cur_scope->__pyx_v_dp_normed_mean = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "pysamstats.pyx":2052
 *         dp_normed_median = dp * 1. / dp_median
 *         dp_normed_mean = dp * 1. / dp_mean
 *         dp_percentile = bisect_left(dp_percentiles, dp)             # <<<<<<<<<<<<<<
 *         dp_normed_median_bygc = dp * 1. / dp_median_bygc[gc]
 *         dp_normed_mean_bygc = dp * 1. / dp_mean_bygc[gc]
 */
    __pyx_t_7 = __Pyx_GetName(__pyx_m, __pyx_n_s__bisect_left); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_dp_percentiles));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_cur_scope->__pyx_v_dp_percentiles));
    __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_dp_percentiles));
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_dp);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_cur_scope->__pyx_v_dp);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_dp);
    __pyx_t_4 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2052; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dp_percentile);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_dp_percentile);
    __Pyx_GIVEREF(__pyx_t_4);
    __pyx_cur_scope->__pyx_v_dp_percentile = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "pysamstats.pyx":2053
 *         dp_normed_mean = dp * 1. / dp_mean
 *         dp_percentile = bisect_left(dp_percentiles, dp)
 *         dp_normed_median_bygc = dp * 1. / dp_median_bygc[gc]             # <<<<<<<<<<<<<<
 *         dp_normed_mean_bygc = dp * 1. / dp_mean_bygc[gc]
 *         dp_percentile_bygc = bisect_left(dp_percentiles_bygc[gc], dp)
 */
    __pyx_t_4 = PyFloat_FromDouble(1.); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = PyNumber_Multiply(__pyx_cur_scope->__pyx_v_dp, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_dp_median_bygc), __pyx_cur_scope->__pyx_v_gc); if (!__pyx_t_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2053; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dp_normed_median_bygc);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_dp_normed_median_bygc);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_cur_scope->__pyx_v_dp_normed_median_bygc = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "pysamstats.pyx":2054
 *         dp_percentile = bisect_left(dp_percentiles, dp)
 *         dp_normed_median_bygc = dp * 1. / dp_median_bygc[gc]
 *         dp_normed_mean_bygc = dp * 1. / dp_mean_bygc[gc]             # <<<<<<<<<<<<<<
 *         dp_percentile_bygc = bisect_left(dp_percentiles_bygc[gc], dp)
 *         rec['dp_normed_median'] = dp_normed_median
 */
    __pyx_t_7 = PyFloat_FromDouble(1.); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_4 = PyNumber_Multiply(__pyx_cur_scope->__pyx_v_dp, __pyx_t_7); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_dp_mean_bygc), __pyx_cur_scope->__pyx_v_gc); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2054; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2054; __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_7); __pyx_t_7 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dp_normed_mean_bygc);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_dp_normed_mean_bygc);
    __Pyx_GIVEREF(__pyx_t_2);
    __pyx_cur_scope->__pyx_v_dp_normed_mean_bygc = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":2055
 *         dp_normed_median_bygc = dp * 1. / dp_median_bygc[gc]
 *         dp_normed_mean_bygc = dp * 1. / dp_mean_bygc[gc]
 *         dp_percentile_bygc = bisect_left(dp_percentiles_bygc[gc], dp)             # <<<<<<<<<<<<<<
 *         rec['dp_normed_median'] = dp_normed_median
 *         rec['dp_normed_mean'] = dp_normed_mean
 */
    __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__bisect_left); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2055; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyDict_GetItem(((PyObject *)__pyx_cur_scope->__pyx_v_dp_percentiles_bygc), __pyx_cur_scope->__pyx_v_gc); if (!__pyx_t_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2055; __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 = 2055; __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_cur_scope->__pyx_v_dp);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_cur_scope->__pyx_v_dp);
    __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_dp);
    __pyx_t_7 = 0;
    __pyx_t_7 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2055; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_dp_percentile_bygc);
    __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_dp_percentile_bygc);
    __Pyx_GIVEREF(__pyx_t_7);
    __pyx_cur_scope->__pyx_v_dp_percentile_bygc = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "pysamstats.pyx":2056
 *         dp_normed_mean_bygc = dp * 1. / dp_mean_bygc[gc]
 *         dp_percentile_bygc = bisect_left(dp_percentiles_bygc[gc], dp)
 *         rec['dp_normed_median'] = dp_normed_median             # <<<<<<<<<<<<<<
 *         rec['dp_normed_mean'] = dp_normed_mean
 *         rec['dp_percentile'] = dp_percentile
 */
    if (PyObject_SetItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__dp_normed_median), __pyx_cur_scope->__pyx_v_dp_normed_median) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2056; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":2057
 *         dp_percentile_bygc = bisect_left(dp_percentiles_bygc[gc], dp)
 *         rec['dp_normed_median'] = dp_normed_median
 *         rec['dp_normed_mean'] = dp_normed_mean             # <<<<<<<<<<<<<<
 *         rec['dp_percentile'] = dp_percentile
 *         rec['dp_normed_median_gc'] = dp_normed_median_bygc
 */
    if (PyObject_SetItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__dp_normed_mean), __pyx_cur_scope->__pyx_v_dp_normed_mean) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2057; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":2058
 *         rec['dp_normed_median'] = dp_normed_median
 *         rec['dp_normed_mean'] = dp_normed_mean
 *         rec['dp_percentile'] = dp_percentile             # <<<<<<<<<<<<<<
 *         rec['dp_normed_median_gc'] = dp_normed_median_bygc
 *         rec['dp_normed_mean_gc'] = dp_normed_mean_bygc
 */
    if (PyObject_SetItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__dp_percentile), __pyx_cur_scope->__pyx_v_dp_percentile) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2058; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":2059
 *         rec['dp_normed_mean'] = dp_normed_mean
 *         rec['dp_percentile'] = dp_percentile
 *         rec['dp_normed_median_gc'] = dp_normed_median_bygc             # <<<<<<<<<<<<<<
 *         rec['dp_normed_mean_gc'] = dp_normed_mean_bygc
 *         rec['dp_percentile_gc'] = dp_percentile_bygc
 */
    if (PyObject_SetItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__dp_normed_median_gc), __pyx_cur_scope->__pyx_v_dp_normed_median_bygc) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2059; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":2060
 *         rec['dp_percentile'] = dp_percentile
 *         rec['dp_normed_median_gc'] = dp_normed_median_bygc
 *         rec['dp_normed_mean_gc'] = dp_normed_mean_bygc             # <<<<<<<<<<<<<<
 *         rec['dp_percentile_gc'] = dp_percentile_bygc
 *         del rec['reads_pp']
 */
    if (PyObject_SetItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__dp_normed_mean_gc), __pyx_cur_scope->__pyx_v_dp_normed_mean_bygc) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2060; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":2061
 *         rec['dp_normed_median_gc'] = dp_normed_median_bygc
 *         rec['dp_normed_mean_gc'] = dp_normed_mean_bygc
 *         rec['dp_percentile_gc'] = dp_percentile_bygc             # <<<<<<<<<<<<<<
 *         del rec['reads_pp']
 *         yield rec
 */
    if (PyObject_SetItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__dp_percentile_gc), __pyx_cur_scope->__pyx_v_dp_percentile_bygc) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":2062
 *         rec['dp_normed_mean_gc'] = dp_normed_mean_bygc
 *         rec['dp_percentile_gc'] = dp_percentile_bygc
 *         del rec['reads_pp']             # <<<<<<<<<<<<<<
 *         yield rec
 * 
 */
    if (unlikely(!__pyx_cur_scope->__pyx_v_rec)) { __Pyx_RaiseUnboundLocalError("rec"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2062; __pyx_clineno = __LINE__; goto __pyx_L1_error;} }
    if (PyObject_DelItem(__pyx_cur_scope->__pyx_v_rec, ((PyObject *)__pyx_n_s__reads_pp)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "pysamstats.pyx":2063
 *         rec['dp_percentile_gc'] = dp_percentile_bygc
 *         del rec['reads_pp']
 *         yield rec             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_INCREF(__pyx_cur_scope->__pyx_v_rec);
    __pyx_r = __pyx_cur_scope->__pyx_v_rec;
    __Pyx_XGIVEREF(__pyx_t_3);
    __pyx_cur_scope->__pyx_t_0 = __pyx_t_3;
    __pyx_cur_scope->__pyx_t_1 = __pyx_t_8;
    __pyx_cur_scope->__pyx_t_2 = __pyx_t_9;
    __Pyx_XGIVEREF(__pyx_r);
    __Pyx_RefNannyFinishContext();
    /* return from generator, yielding value */
    __pyx_generator->resume_label = 1;
    return __pyx_r;
    __pyx_L15_resume_from_yield:;
    __pyx_t_3 = __pyx_cur_scope->__pyx_t_0;
    __pyx_cur_scope->__pyx_t_0 = 0;
    __Pyx_XGOTREF(__pyx_t_3);
    __pyx_t_8 = __pyx_cur_scope->__pyx_t_1;
    __pyx_t_9 = __pyx_cur_scope->__pyx_t_2;
    if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  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_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("stat_coverage_normed_gc", __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;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_112write_coverage_normed_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_112write_coverage_normed_gc = {__Pyx_NAMESTR("write_coverage_normed_gc"), (PyCFunction)__pyx_pw_10pysamstats_112write_coverage_normed_gc, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_112write_coverage_normed_gc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_args = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_coverage_normed_gc (wrapper)", 0);
  if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "write_coverage_normed_gc", 1))) return NULL;
  __pyx_v_kwargs = (__pyx_kwds) ? PyDict_Copy(__pyx_kwds) : PyDict_New();
  if (unlikely(!__pyx_v_kwargs)) return NULL;
  __Pyx_GOTREF(__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_args);
  __pyx_v_args = __pyx_args;
  __pyx_r = __pyx_pf_10pysamstats_111write_coverage_normed_gc(__pyx_self, __pyx_v_args, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2066
 * 
 * 
 * def write_coverage_normed_gc(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'gc',
 *                   'reads_all', #'reads_pp',
 */

static PyObject *__pyx_pf_10pysamstats_111write_coverage_normed_gc(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
  PyObject *__pyx_v_fieldnames = 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_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_coverage_normed_gc", 0);

  /* "pysamstats.pyx":2067
 * 
 * def write_coverage_normed_gc(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'gc',             # <<<<<<<<<<<<<<
 *                   'reads_all', #'reads_pp',
 *                   'dp_normed_median',
 */
  __Pyx_INCREF(((PyObject *)__pyx_k_tuple_63));
  __pyx_v_fieldnames = __pyx_k_tuple_63;

  /* "pysamstats.pyx":2075
 *                   'dp_normed_mean_gc',
 *                   'dp_percentile_gc')
 *     write_stats(stat_coverage_normed_gc, fieldnames, *args, **kwargs)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__write_stats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s_64); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2075; __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 = 2075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_v_fieldnames));
  PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_fieldnames));
  __pyx_t_2 = 0;
  __pyx_t_2 = PySequence_Tuple(((PyObject *)__pyx_v_args)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  __pyx_t_4 = PyNumber_Add(((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_4));
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_v_kwargs);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_4), ((PyObject *)__pyx_t_2)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2075; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.write_coverage_normed_gc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_fieldnames);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_114normalise_coords(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_114normalise_coords = {__Pyx_NAMESTR("normalise_coords"), (PyCFunction)__pyx_pw_10pysamstats_114normalise_coords, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_114normalise_coords(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("normalise_coords (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,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__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("normalise_coords", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("normalise_coords", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "normalise_coords") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __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_start = values[0];
    __pyx_v_end = values[1];
    __pyx_v_one_based = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("normalise_coords", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("pysamstats.normalise_coords", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_113normalise_coords(__pyx_self, __pyx_v_start, __pyx_v_end, __pyx_v_one_based);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2083
 * 
 * 
 * def normalise_coords(start, end, one_based):             # <<<<<<<<<<<<<<
 *     if one_based:
 *         start = start - 1 if start is not None else None
 */

static PyObject *__pyx_pf_10pysamstats_113normalise_coords(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("normalise_coords", 0);
  __Pyx_INCREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);

  /* "pysamstats.pyx":2084
 * 
 * def normalise_coords(start, end, one_based):
 *     if one_based:             # <<<<<<<<<<<<<<
 *         start = start - 1 if start is not None else None
 *         end = end - 1 if end is not None else None
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_one_based); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2084; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "pysamstats.pyx":2085
 * def normalise_coords(start, end, one_based):
 *     if one_based:
 *         start = start - 1 if start is not None else None             # <<<<<<<<<<<<<<
 *         end = end - 1 if end is not None else None
 *     return start, end
 */
    __pyx_t_1 = (__pyx_v_start != Py_None);
    if (__pyx_t_1) {
      __pyx_t_3 = PyNumber_Subtract(__pyx_v_start, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2085; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __pyx_t_3;
      __pyx_t_3 = 0;
    } else {
      __Pyx_INCREF(Py_None);
      __pyx_t_2 = Py_None;
    }
    __Pyx_DECREF(__pyx_v_start);
    __pyx_v_start = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "pysamstats.pyx":2086
 *     if one_based:
 *         start = start - 1 if start is not None else None
 *         end = end - 1 if end is not None else None             # <<<<<<<<<<<<<<
 *     return start, end
 * 
 */
    __pyx_t_1 = (__pyx_v_end != Py_None);
    if (__pyx_t_1) {
      __pyx_t_3 = PyNumber_Subtract(__pyx_v_end, __pyx_int_1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2086; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = __pyx_t_3;
      __pyx_t_3 = 0;
    } else {
      __Pyx_INCREF(Py_None);
      __pyx_t_2 = Py_None;
    }
    __Pyx_DECREF(__pyx_v_end);
    __pyx_v_end = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":2087
 *         start = start - 1 if start is not None else None
 *         end = end - 1 if end is not None else None
 *     return start, end             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_start);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_start);
  __Pyx_GIVEREF(__pyx_v_start);
  __Pyx_INCREF(__pyx_v_end);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_end);
  __Pyx_GIVEREF(__pyx_v_end);
  __pyx_r = ((PyObject *)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("pysamstats.normalise_coords", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_start);
  __Pyx_XDECREF(__pyx_v_end);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_10pysamstats_116write_stats(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_10pysamstats_116write_stats = {__Pyx_NAMESTR("write_stats"), (PyCFunction)__pyx_pw_10pysamstats_116write_stats, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)};
static PyObject *__pyx_pw_10pysamstats_116write_stats(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_statfun = 0;
  PyObject *__pyx_v_fieldnames = 0;
  PyObject *__pyx_v_outfile = 0;
  PyObject *__pyx_v_samfile = 0;
  PyObject *__pyx_v_fafile = 0;
  PyObject *__pyx_v_dialect = 0;
  PyObject *__pyx_v_write_header = 0;
  PyObject *__pyx_v_chrom = 0;
  PyObject *__pyx_v_start = 0;
  PyObject *__pyx_v_end = 0;
  PyObject *__pyx_v_one_based = 0;
  PyObject *__pyx_v_progress = 0;
  PyObject *__pyx_v_kwargs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_stats (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__statfun,&__pyx_n_s__fieldnames,&__pyx_n_s__outfile,&__pyx_n_s__samfile,&__pyx_n_s__fafile,&__pyx_n_s__dialect,&__pyx_n_s__write_header,&__pyx_n_s__chrom,&__pyx_n_s__start,&__pyx_n_s__end,&__pyx_n_s__one_based,&__pyx_n_s__progress,0};
    PyObject* values[12] = {0,0,0,0,0,0,0,0,0,0,0,0};

    /* "pysamstats.pyx":2090
 * 
 * 
 * def write_stats(statfun, fieldnames, outfile, samfile, fafile=None,             # <<<<<<<<<<<<<<
 *                 dialect=csv.excel_tab, write_header=True,
 *                 chrom=None, start=None, end=None,
 */
    values[4] = ((PyObject *)Py_None);
    values[5] = __pyx_k_65;
    values[6] = __pyx_k_66;

    /* "pysamstats.pyx":2092
 * def write_stats(statfun, fieldnames, outfile, samfile, fafile=None,
 *                 dialect=csv.excel_tab, write_header=True,
 *                 chrom=None, start=None, end=None,             # <<<<<<<<<<<<<<
 *                 one_based=False, progress=None, **kwargs):
 *     cdef long long counter = 0
 */
    values[7] = ((PyObject *)Py_None);
    values[8] = ((PyObject *)Py_None);
    values[9] = ((PyObject *)Py_None);
    values[10] = __pyx_k_67;

    /* "pysamstats.pyx":2093
 *                 dialect=csv.excel_tab, write_header=True,
 *                 chrom=None, start=None, end=None,
 *                 one_based=False, progress=None, **kwargs):             # <<<<<<<<<<<<<<
 *     cdef long long counter = 0
 *     cdef long long modulus
 */
    values[11] = ((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 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__statfun)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fieldnames)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("write_stats", 0, 4, 12, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__outfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("write_stats", 0, 4, 12, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__samfile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("write_stats", 0, 4, 12, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__fafile);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__dialect);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__write_header);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__chrom);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__start);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__end);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__one_based);
          if (value) { values[10] = value; kw_args--; }
        }
        case 11:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__progress);
          if (value) { values[11] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "write_stats") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        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);
        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_statfun = values[0];
    __pyx_v_fieldnames = values[1];
    __pyx_v_outfile = values[2];
    __pyx_v_samfile = values[3];
    __pyx_v_fafile = values[4];
    __pyx_v_dialect = values[5];
    __pyx_v_write_header = values[6];
    __pyx_v_chrom = values[7];
    __pyx_v_start = values[8];
    __pyx_v_end = values[9];
    __pyx_v_one_based = values[10];
    __pyx_v_progress = values[11];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("write_stats", 0, 4, 12, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
  __Pyx_AddTraceback("pysamstats.write_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_10pysamstats_115write_stats(__pyx_self, __pyx_v_statfun, __pyx_v_fieldnames, __pyx_v_outfile, __pyx_v_samfile, __pyx_v_fafile, __pyx_v_dialect, __pyx_v_write_header, __pyx_v_chrom, __pyx_v_start, __pyx_v_end, __pyx_v_one_based, __pyx_v_progress, __pyx_v_kwargs);
  __Pyx_XDECREF(__pyx_v_kwargs);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2090
 * 
 * 
 * def write_stats(statfun, fieldnames, outfile, samfile, fafile=None,             # <<<<<<<<<<<<<<
 *                 dialect=csv.excel_tab, write_header=True,
 *                 chrom=None, start=None, end=None,
 */

static PyObject *__pyx_pf_10pysamstats_115write_stats(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_statfun, PyObject *__pyx_v_fieldnames, PyObject *__pyx_v_outfile, PyObject *__pyx_v_samfile, PyObject *__pyx_v_fafile, PyObject *__pyx_v_dialect, PyObject *__pyx_v_write_header, PyObject *__pyx_v_chrom, PyObject *__pyx_v_start, PyObject *__pyx_v_end, PyObject *__pyx_v_one_based, PyObject *__pyx_v_progress, PyObject *__pyx_v_kwargs) {
  PY_LONG_LONG __pyx_v_counter;
  PY_LONG_LONG __pyx_v_modulus;
  PyObject *__pyx_v_writer = NULL;
  PyObject *__pyx_v_recs = NULL;
  PyObject *__pyx_v_before = NULL;
  PyObject *__pyx_v_before_all = NULL;
  PyObject *__pyx_v_rec = NULL;
  PyObject *__pyx_v_after = NULL;
  PyObject *__pyx_v_elapsed = NULL;
  PyObject *__pyx_v_batch_elapsed = NULL;
  PyObject *__pyx_v_after_all = NULL;
  PyObject *__pyx_v_elapsed_all = 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;
  PY_LONG_LONG __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("write_stats", 0);

  /* "pysamstats.pyx":2094
 *                 chrom=None, start=None, end=None,
 *                 one_based=False, progress=None, **kwargs):
 *     cdef long long counter = 0             # <<<<<<<<<<<<<<
 *     cdef long long modulus
 * 
 */
  __pyx_v_counter = 0;

  /* "pysamstats.pyx":2097
 *     cdef long long modulus
 * 
 *     writer = csv.DictWriter(outfile, fieldnames, dialect=dialect)             # <<<<<<<<<<<<<<
 * 
 *     if write_header:
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__csv); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__DictWriter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_outfile);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_outfile);
  __Pyx_GIVEREF(__pyx_v_outfile);
  __Pyx_INCREF(__pyx_v_fieldnames);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_fieldnames);
  __Pyx_GIVEREF(__pyx_v_fieldnames);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_3));
  if (PyDict_SetItem(__pyx_t_3, ((PyObject *)__pyx_n_s__dialect), __pyx_v_dialect) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2097; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
  __pyx_v_writer = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "pysamstats.pyx":2099
 *     writer = csv.DictWriter(outfile, fieldnames, dialect=dialect)
 * 
 *     if write_header:             # <<<<<<<<<<<<<<
 *         writer.writeheader()
 * 
 */
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_v_write_header); if (unlikely(__pyx_t_5 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2099; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_5) {

    /* "pysamstats.pyx":2100
 * 
 *     if write_header:
 *         writer.writeheader()             # <<<<<<<<<<<<<<
 * 
 *     if fafile is None:
 */
    __pyx_t_4 = PyObject_GetAttr(__pyx_v_writer, __pyx_n_s__writeheader); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2100; __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_3); __pyx_t_3 = 0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":2102
 *         writer.writeheader()
 * 
 *     if fafile is None:             # <<<<<<<<<<<<<<
 *         recs = statfun(samfile, chrom=chrom, start=start, end=end, one_based=one_based, **kwargs)
 *     else:
 */
  __pyx_t_5 = (__pyx_v_fafile == Py_None);
  if (__pyx_t_5) {

    /* "pysamstats.pyx":2103
 * 
 *     if fafile is None:
 *         recs = statfun(samfile, chrom=chrom, start=start, end=end, one_based=one_based, **kwargs)             # <<<<<<<<<<<<<<
 *     else:
 *         recs = statfun(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based, **kwargs)
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_samfile);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_samfile);
    __Pyx_GIVEREF(__pyx_v_samfile);
    __pyx_t_4 = PyDict_Copy(((PyObject *)__pyx_v_kwargs)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    if (unlikely(PyDict_GetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom)))) {
      __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__chrom)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__start)))) {
      __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__start)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__start), __pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__end)))) {
      __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__end)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__end), __pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__one_based)))) {
      __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__one_based)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__one_based), __pyx_v_one_based) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_1 = PyObject_Call(__pyx_v_statfun, ((PyObject *)__pyx_t_3), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __pyx_v_recs = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "pysamstats.pyx":2105
 *         recs = statfun(samfile, chrom=chrom, start=start, end=end, one_based=one_based, **kwargs)
 *     else:
 *         recs = statfun(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based, **kwargs)             # <<<<<<<<<<<<<<
 * 
 *     if progress is None:
 */
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_samfile);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_samfile);
    __Pyx_GIVEREF(__pyx_v_samfile);
    __Pyx_INCREF(__pyx_v_fafile);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_fafile);
    __Pyx_GIVEREF(__pyx_v_fafile);
    __pyx_t_4 = PyDict_Copy(((PyObject *)__pyx_v_kwargs)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_4));
    if (unlikely(PyDict_GetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom)))) {
      __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__chrom)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__chrom), __pyx_v_chrom) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__start)))) {
      __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__start)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__start), __pyx_v_start) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__end)))) {
      __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__end)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__end), __pyx_v_end) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (unlikely(PyDict_GetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__one_based)))) {
      __Pyx_RaiseDoubleKeywordsError("function", ((PyObject *)__pyx_n_s__one_based)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (PyDict_SetItem(__pyx_t_4, ((PyObject *)__pyx_n_s__one_based), __pyx_v_one_based) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = PyObject_Call(__pyx_v_statfun, ((PyObject *)__pyx_t_1), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2105; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __pyx_v_recs = __pyx_t_3;
    __pyx_t_3 = 0;
  }
  __pyx_L4:;

  /* "pysamstats.pyx":2107
 *         recs = statfun(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based, **kwargs)
 * 
 *     if progress is None:             # <<<<<<<<<<<<<<
 *         writer.writerows(recs)
 * 
 */
  __pyx_t_5 = (__pyx_v_progress == Py_None);
  if (__pyx_t_5) {

    /* "pysamstats.pyx":2108
 * 
 *     if progress is None:
 *         writer.writerows(recs)             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
    __pyx_t_3 = PyObject_GetAttr(__pyx_v_writer, __pyx_n_s__writerows); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_recs);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_recs);
    __Pyx_GIVEREF(__pyx_v_recs);
    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2108; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L5;
  }
  /*else*/ {

    /* "pysamstats.pyx":2111
 * 
 *     else:
 *         modulus = progress             # <<<<<<<<<<<<<<
 *         before = time.time()
 *         before_all = before
 */
    __pyx_t_6 = __Pyx_PyInt_AsLongLong(__pyx_v_progress); if (unlikely((__pyx_t_6 == (PY_LONG_LONG)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2111; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_modulus = __pyx_t_6;

    /* "pysamstats.pyx":2112
 *     else:
 *         modulus = progress
 *         before = time.time()             # <<<<<<<<<<<<<<
 *         before_all = before
 *         for rec in recs:
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__time); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__time); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2112; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_before = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "pysamstats.pyx":2113
 *         modulus = progress
 *         before = time.time()
 *         before_all = before             # <<<<<<<<<<<<<<
 *         for rec in recs:
 *             counter += 1
 */
    __Pyx_INCREF(__pyx_v_before);
    __pyx_v_before_all = __pyx_v_before;

    /* "pysamstats.pyx":2114
 *         before = time.time()
 *         before_all = before
 *         for rec in recs:             # <<<<<<<<<<<<<<
 *             counter += 1
 *             writer.writerow(rec)
 */
    if (PyList_CheckExact(__pyx_v_recs) || PyTuple_CheckExact(__pyx_v_recs)) {
      __pyx_t_1 = __pyx_v_recs; __Pyx_INCREF(__pyx_t_1); __pyx_t_7 = 0;
      __pyx_t_8 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_recs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_8 = Py_TYPE(__pyx_t_1)->tp_iternext;
    }
    for (;;) {
      if (!__pyx_t_8 && PyList_CheckExact(__pyx_t_1)) {
        if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else if (!__pyx_t_8 && PyTuple_CheckExact(__pyx_t_1)) {
        if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_4); __pyx_t_7++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #endif
      } else {
        __pyx_t_4 = __pyx_t_8(__pyx_t_1);
        if (unlikely(!__pyx_t_4)) {
          if (PyErr_Occurred()) {
            if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear();
            else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2114; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_4);
      }
      __Pyx_XDECREF(__pyx_v_rec);
      __pyx_v_rec = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "pysamstats.pyx":2115
 *         before_all = before
 *         for rec in recs:
 *             counter += 1             # <<<<<<<<<<<<<<
 *             writer.writerow(rec)
 *             if counter % modulus == 0:
 */
      __pyx_v_counter = (__pyx_v_counter + 1);

      /* "pysamstats.pyx":2116
 *         for rec in recs:
 *             counter += 1
 *             writer.writerow(rec)             # <<<<<<<<<<<<<<
 *             if counter % modulus == 0:
 *                 after = time.time()
 */
      __pyx_t_4 = PyObject_GetAttr(__pyx_v_writer, __pyx_n_s__writerow); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_v_rec);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_rec);
      __Pyx_GIVEREF(__pyx_v_rec);
      __pyx_t_2 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2116; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "pysamstats.pyx":2117
 *             counter += 1
 *             writer.writerow(rec)
 *             if counter % modulus == 0:             # <<<<<<<<<<<<<<
 *                 after = time.time()
 *                 elapsed = after - before_all
 */
      if (unlikely(__pyx_v_modulus == 0)) {
        PyErr_Format(PyExc_ZeroDivisionError, "integer division or modulo by zero");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_5 = (__Pyx_mod_PY_LONG_LONG(__pyx_v_counter, __pyx_v_modulus) == 0);
      if (__pyx_t_5) {

        /* "pysamstats.pyx":2118
 *             writer.writerow(rec)
 *             if counter % modulus == 0:
 *                 after = time.time()             # <<<<<<<<<<<<<<
 *                 elapsed = after - before_all
 *                 batch_elapsed = after - before
 */
        __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__time); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__time); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_v_after);
        __pyx_v_after = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "pysamstats.pyx":2119
 *             if counter % modulus == 0:
 *                 after = time.time()
 *                 elapsed = after - before_all             # <<<<<<<<<<<<<<
 *                 batch_elapsed = after - before
 *                 print >>sys.stderr, '%s rows in %.2fs (%d rows/s); batch in %.2fs (%d rows/s)' % (counter, elapsed, counter/elapsed, batch_elapsed, progress/batch_elapsed)
 */
        __pyx_t_2 = PyNumber_Subtract(__pyx_v_after, __pyx_v_before_all); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_XDECREF(__pyx_v_elapsed);
        __pyx_v_elapsed = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "pysamstats.pyx":2120
 *                 after = time.time()
 *                 elapsed = after - before_all
 *                 batch_elapsed = after - before             # <<<<<<<<<<<<<<
 *                 print >>sys.stderr, '%s rows in %.2fs (%d rows/s); batch in %.2fs (%d rows/s)' % (counter, elapsed, counter/elapsed, batch_elapsed, progress/batch_elapsed)
 *                 before = after
 */
        __pyx_t_2 = PyNumber_Subtract(__pyx_v_after, __pyx_v_before); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2120; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_XDECREF(__pyx_v_batch_elapsed);
        __pyx_v_batch_elapsed = __pyx_t_2;
        __pyx_t_2 = 0;

        /* "pysamstats.pyx":2121
 *                 elapsed = after - before_all
 *                 batch_elapsed = after - before
 *                 print >>sys.stderr, '%s rows in %.2fs (%d rows/s); batch in %.2fs (%d rows/s)' % (counter, elapsed, counter/elapsed, batch_elapsed, progress/batch_elapsed)             # <<<<<<<<<<<<<<
 *                 before = after
 *         after_all = time.time()
 */
        __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__stderr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyLong_FromLongLong(__pyx_v_counter); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_4 = PyLong_FromLongLong(__pyx_v_counter); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_9 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_v_elapsed); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_v_progress, __pyx_v_batch_elapsed); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_10 = PyTuple_New(5); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        __Pyx_INCREF(__pyx_v_elapsed);
        PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_elapsed);
        __Pyx_GIVEREF(__pyx_v_elapsed);
        PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_9);
        __Pyx_INCREF(__pyx_v_batch_elapsed);
        PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_v_batch_elapsed);
        __Pyx_GIVEREF(__pyx_v_batch_elapsed);
        PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_4);
        __pyx_t_2 = 0;
        __pyx_t_9 = 0;
        __pyx_t_4 = 0;
        __pyx_t_4 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_68), ((PyObject *)__pyx_t_10)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_4));
        __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
        if (__Pyx_PrintOne(__pyx_t_3, ((PyObject *)__pyx_t_4)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "pysamstats.pyx":2122
 *                 batch_elapsed = after - before
 *                 print >>sys.stderr, '%s rows in %.2fs (%d rows/s); batch in %.2fs (%d rows/s)' % (counter, elapsed, counter/elapsed, batch_elapsed, progress/batch_elapsed)
 *                 before = after             # <<<<<<<<<<<<<<
 *         after_all = time.time()
 *         elapsed_all = after_all - before_all
 */
        __Pyx_INCREF(__pyx_v_after);
        __Pyx_DECREF(__pyx_v_before);
        __pyx_v_before = __pyx_v_after;
        goto __pyx_L8;
      }
      __pyx_L8:;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "pysamstats.pyx":2123
 *                 print >>sys.stderr, '%s rows in %.2fs (%d rows/s); batch in %.2fs (%d rows/s)' % (counter, elapsed, counter/elapsed, batch_elapsed, progress/batch_elapsed)
 *                 before = after
 *         after_all = time.time()             # <<<<<<<<<<<<<<
 *         elapsed_all = after_all - before_all
 *         print >>sys.stderr, '%s rows in %.2fs (%d rows/s)' % (counter, elapsed_all, counter/elapsed_all)
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__time); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__time); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_after_all = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "pysamstats.pyx":2124
 *                 before = after
 *         after_all = time.time()
 *         elapsed_all = after_all - before_all             # <<<<<<<<<<<<<<
 *         print >>sys.stderr, '%s rows in %.2fs (%d rows/s)' % (counter, elapsed_all, counter/elapsed_all)
 * 
 */
    __pyx_t_1 = PyNumber_Subtract(__pyx_v_after_all, __pyx_v_before_all); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_elapsed_all = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "pysamstats.pyx":2125
 *         after_all = time.time()
 *         elapsed_all = after_all - before_all
 *         print >>sys.stderr, '%s rows in %.2fs (%d rows/s)' % (counter, elapsed_all, counter/elapsed_all)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__sys); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__stderr); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyLong_FromLongLong(__pyx_v_counter); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyLong_FromLongLong(__pyx_v_counter); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_10 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_v_elapsed_all); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_elapsed_all);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_elapsed_all);
    __Pyx_GIVEREF(__pyx_v_elapsed_all);
    PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_10);
    __pyx_t_1 = 0;
    __pyx_t_10 = 0;
    __pyx_t_10 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_69), ((PyObject *)__pyx_t_4)); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(((PyObject *)__pyx_t_10));
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    if (__Pyx_PrintOne(__pyx_t_3, ((PyObject *)__pyx_t_10)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2125; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __pyx_L5:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("pysamstats.write_stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_writer);
  __Pyx_XDECREF(__pyx_v_recs);
  __Pyx_XDECREF(__pyx_v_before);
  __Pyx_XDECREF(__pyx_v_before_all);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XDECREF(__pyx_v_after);
  __Pyx_XDECREF(__pyx_v_elapsed);
  __Pyx_XDECREF(__pyx_v_batch_elapsed);
  __Pyx_XDECREF(__pyx_v_after_all);
  __Pyx_XDECREF(__pyx_v_elapsed_all);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2128
 * 
 * 
 * cdef inline bint is_softclipped(bam1_t * aln):             # <<<<<<<<<<<<<<
 *     cigar_p = bam1_cigar(aln);
 *     for k in range(aln.core.n_cigar):
 */

static CYTHON_INLINE int __pyx_f_10pysamstats_is_softclipped(bam1_t *__pyx_v_aln) {
  uint32_t *__pyx_v_cigar_p;
  uint32_t __pyx_v_k;
  long __pyx_v_op;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  uint32_t __pyx_t_1;
  uint32_t __pyx_t_2;
  int __pyx_t_3;
  __Pyx_RefNannySetupContext("is_softclipped", 0);

  /* "pysamstats.pyx":2129
 * 
 * cdef inline bint is_softclipped(bam1_t * aln):
 *     cigar_p = bam1_cigar(aln);             # <<<<<<<<<<<<<<
 *     for k in range(aln.core.n_cigar):
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 */
  __pyx_v_cigar_p = bam1_cigar(__pyx_v_aln);

  /* "pysamstats.pyx":2130
 * cdef inline bint is_softclipped(bam1_t * aln):
 *     cigar_p = bam1_cigar(aln);
 *     for k in range(aln.core.n_cigar):             # <<<<<<<<<<<<<<
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         if op == BAM_CSOFT_CLIP:
 */
  __pyx_t_1 = __pyx_v_aln->core.n_cigar;
  for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
    __pyx_v_k = __pyx_t_2;

    /* "pysamstats.pyx":2131
 *     cigar_p = bam1_cigar(aln);
 *     for k in range(aln.core.n_cigar):
 *         op = cigar_p[k] & BAM_CIGAR_MASK             # <<<<<<<<<<<<<<
 *         if op == BAM_CSOFT_CLIP:
 *             return 1
 */
    __pyx_v_op = ((__pyx_v_cigar_p[__pyx_v_k]) & 15);

    /* "pysamstats.pyx":2132
 *     for k in range(aln.core.n_cigar):
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         if op == BAM_CSOFT_CLIP:             # <<<<<<<<<<<<<<
 *             return 1
 *     return 0
 */
    __pyx_t_3 = (__pyx_v_op == 4);
    if (__pyx_t_3) {

      /* "pysamstats.pyx":2133
 *         op = cigar_p[k] & BAM_CIGAR_MASK
 *         if op == BAM_CSOFT_CLIP:
 *             return 1             # <<<<<<<<<<<<<<
 *     return 0
 * 
 */
      __pyx_r = 1;
      goto __pyx_L0;
      goto __pyx_L5;
    }
    __pyx_L5:;
  }

  /* "pysamstats.pyx":2134
 *         if op == BAM_CSOFT_CLIP:
 *             return 1
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = 0;
  goto __pyx_L0;

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

/* "pysamstats.pyx":2137
 * 
 * 
 * cdef inline object get_seq_base(bam1_t *src, uint32_t k):             # <<<<<<<<<<<<<<
 *     cdef uint8_t * p
 *     cdef char * s
 */

static CYTHON_INLINE PyObject *__pyx_f_10pysamstats_get_seq_base(bam1_t *__pyx_v_src, uint32_t __pyx_v_k) {
  uint8_t *__pyx_v_p;
  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;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("get_seq_base", 0);

  /* "pysamstats.pyx":2141
 *     cdef char * s
 * 
 *     if not src.core.l_qseq:             # <<<<<<<<<<<<<<
 *         return None
 * 
 */
  __pyx_t_1 = (!__pyx_v_src->core.l_qseq);
  if (__pyx_t_1) {

    /* "pysamstats.pyx":2142
 * 
 *     if not src.core.l_qseq:
 *         return None             # <<<<<<<<<<<<<<
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, 1)
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "pysamstats.pyx":2144
 *         return None
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, 1)             # <<<<<<<<<<<<<<
 *     s   = <char*>seq
 *     p   = bam1_seq(src)
 */
  __pyx_t_2 = ((PyObject *)PyBytes_FromStringAndSize(NULL, 1)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2144; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_seq = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":2145
 * 
 *     seq = PyBytes_FromStringAndSize(NULL, 1)
 *     s   = <char*>seq             # <<<<<<<<<<<<<<
 *     p   = bam1_seq(src)
 * 
 */
  __pyx_t_3 = PyBytes_AsString(((PyObject *)__pyx_v_seq)); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2145; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_s = ((char *)__pyx_t_3);

  /* "pysamstats.pyx":2146
 *     seq = PyBytes_FromStringAndSize(NULL, 1)
 *     s   = <char*>seq
 *     p   = bam1_seq(src)             # <<<<<<<<<<<<<<
 * 
 *     # equivalent to bam_nt16_rev_table[bam1_seqi(s, i)] (see bam.c)
 */
  __pyx_v_p = ((uint8_t *)bam1_seq(__pyx_v_src));

  /* "pysamstats.pyx":2150
 *     # equivalent to bam_nt16_rev_table[bam1_seqi(s, i)] (see bam.c)
 *     # note: do not use string literal as it will be a python string
 *     s[0] = bam_nt16_rev_table[p[k/2] >> 4 * (1 - k%2) & 0xf]             # <<<<<<<<<<<<<<
 * 
 *     return seq
 */
  (__pyx_v_s[0]) = (__pyx_v_10pysamstats_bam_nt16_rev_table[(((__pyx_v_p[__Pyx_div_long(__pyx_v_k, 2)]) >> (4 * (1 - __Pyx_mod_long(__pyx_v_k, 2)))) & 0xf)]);

  /* "pysamstats.pyx":2152
 *     s[0] = bam_nt16_rev_table[p[k/2] >> 4 * (1 - k%2) & 0xf]
 * 
 *     return seq             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_seq));
  __pyx_r = ((PyObject *)__pyx_v_seq);
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("pysamstats.get_seq_base", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_seq);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "pysamstats.pyx":2155
 * 
 * 
 * cdef inline object rootmean(uint64_t sqsum, unsigned int count):             # <<<<<<<<<<<<<<
 *     if count > 0:
 *         return int(round(sqrt(sqsum * 1. / count)))
 */

static CYTHON_INLINE PyObject *__pyx_f_10pysamstats_rootmean(uint64_t __pyx_v_sqsum, unsigned int __pyx_v_count) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  double __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_RefNannySetupContext("rootmean", 0);

  /* "pysamstats.pyx":2156
 * 
 * cdef inline object rootmean(uint64_t sqsum, unsigned int count):
 *     if count > 0:             # <<<<<<<<<<<<<<
 *         return int(round(sqrt(sqsum * 1. / count)))
 *     else:
 */
  __pyx_t_1 = (__pyx_v_count > 0);
  if (__pyx_t_1) {

    /* "pysamstats.pyx":2157
 * cdef inline object rootmean(uint64_t sqsum, unsigned int count):
 *     if count > 0:
 *         return int(round(sqrt(sqsum * 1. / count)))             # <<<<<<<<<<<<<<
 *     else:
 *         return 'NA'
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = (__pyx_v_sqsum * 1.);
    if (unlikely(__pyx_v_count == 0)) {
      PyErr_Format(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_3 = PyFloat_FromDouble(sqrt((__pyx_t_2 / __pyx_v_count))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(__pyx_builtin_round, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__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 = 2157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyInt_Type))), ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2157; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "pysamstats.pyx":2159
 *         return int(round(sqrt(sqsum * 1. / count)))
 *     else:
 *         return 'NA'             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_n_s__NA));
    __pyx_r = ((PyObject *)__pyx_n_s__NA);
    goto __pyx_L0;
  }
  __pyx_L3:;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("pysamstats.rootmean", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_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_5numpy_7ndarray___getbuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":194
 *         # experimental exception made for __getbuffer__ and __releasebuffer__
 *         # -- the details of this may change.
 *         def __getbuffer__(ndarray self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fullfill the PEP.
 */

static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_v_copy_shape;
  int __pyx_v_i;
  int __pyx_v_ndim;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  int __pyx_v_t;
  char *__pyx_v_f;
  PyArray_Descr *__pyx_v_descr = 0;
  int __pyx_v_offset;
  int __pyx_v_hasfields;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  char *__pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __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);
  }

  /* "numpy.pxd":200
 *             # of flags
 * 
 *             if info == NULL: return             # <<<<<<<<<<<<<<
 * 
 *             cdef int copy_shape, i, ndim
 */
  __pyx_t_1 = (__pyx_v_info == NULL);
  if (__pyx_t_1) {
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "numpy.pxd":203
 * 
 *             cdef int copy_shape, i, ndim
 *             cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 */
  __pyx_v_endian_detector = 1;

  /* "numpy.pxd":204
 *             cdef int copy_shape, i, ndim
 *             cdef int endian_detector = 1
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 * 
 *             ndim = PyArray_NDIM(self)
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "numpy.pxd":206
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 *             ndim = PyArray_NDIM(self)             # <<<<<<<<<<<<<<
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_v_ndim = PyArray_NDIM(__pyx_v_self);

  /* "numpy.pxd":208
 *             ndim = PyArray_NDIM(self)
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 copy_shape = 1
 *             else:
 */
  __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t)));
  if (__pyx_t_1) {

    /* "numpy.pxd":209
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 copy_shape = 1             # <<<<<<<<<<<<<<
 *             else:
 *                 copy_shape = 0
 */
    __pyx_v_copy_shape = 1;
    goto __pyx_L4;
  }
  /*else*/ {

    /* "numpy.pxd":211
 *                 copy_shape = 1
 *             else:
 *                 copy_shape = 0             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 */
    __pyx_v_copy_shape = 0;
  }
  __pyx_L4:;

  /* "numpy.pxd":213
 *                 copy_shape = 0
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  __pyx_t_1 = ((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS);
  if (__pyx_t_1) {

    /* "numpy.pxd":214
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 */
    __pyx_t_2 = (!PyArray_CHKFLAGS(__pyx_v_self, NPY_C_CONTIGUOUS));
    __pyx_t_3 = __pyx_t_2;
  } else {
    __pyx_t_3 = __pyx_t_1;
  }
  if (__pyx_t_3) {

    /* "numpy.pxd":215
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_71), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __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[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "numpy.pxd":217
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  __pyx_t_3 = ((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS);
  if (__pyx_t_3) {

    /* "numpy.pxd":218
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 */
    __pyx_t_1 = (!PyArray_CHKFLAGS(__pyx_v_self, NPY_F_CONTIGUOUS));
    __pyx_t_2 = __pyx_t_1;
  } else {
    __pyx_t_2 = __pyx_t_3;
  }
  if (__pyx_t_2) {

    /* "numpy.pxd":219
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
    __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_73), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __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[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "numpy.pxd":221
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 *             info.buf = PyArray_DATA(self)             # <<<<<<<<<<<<<<
 *             info.ndim = ndim
 *             if copy_shape:
 */
  __pyx_v_info->buf = PyArray_DATA(__pyx_v_self);

  /* "numpy.pxd":222
 * 
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim             # <<<<<<<<<<<<<<
 *             if copy_shape:
 *                 # Allocate new buffer for strides and shape info.
 */
  __pyx_v_info->ndim = __pyx_v_ndim;

  /* "numpy.pxd":223
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim
 *             if copy_shape:             # <<<<<<<<<<<<<<
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 */
  if (__pyx_v_copy_shape) {

    /* "numpy.pxd":226
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)             # <<<<<<<<<<<<<<
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 */
    __pyx_v_info->strides = ((Py_ssize_t *)malloc((((sizeof(Py_ssize_t)) * ((size_t)__pyx_v_ndim)) * 2)));

    /* "numpy.pxd":227
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)
 *                 info.shape = info.strides + ndim             # <<<<<<<<<<<<<<
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 */
    __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim);

    /* "numpy.pxd":228
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):             # <<<<<<<<<<<<<<
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 */
    __pyx_t_5 = __pyx_v_ndim;
    for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
      __pyx_v_i = __pyx_t_6;

      /* "numpy.pxd":229
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]             # <<<<<<<<<<<<<<
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 */
      (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(__pyx_v_self)[__pyx_v_i]);

      /* "numpy.pxd":230
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]             # <<<<<<<<<<<<<<
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 */
      (__pyx_v_info->shape[__pyx_v_i]) = (PyArray_DIMS(__pyx_v_self)[__pyx_v_i]);
    }
    goto __pyx_L7;
  }
  /*else*/ {

    /* "numpy.pxd":232
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)             # <<<<<<<<<<<<<<
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 */
    __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(__pyx_v_self));

    /* "numpy.pxd":233
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)             # <<<<<<<<<<<<<<
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 */
    __pyx_v_info->shape = ((Py_ssize_t *)PyArray_DIMS(__pyx_v_self));
  }
  __pyx_L7:;

  /* "numpy.pxd":234
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 */
  __pyx_v_info->suboffsets = NULL;

  /* "numpy.pxd":235
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)             # <<<<<<<<<<<<<<
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 * 
 */
  __pyx_v_info->itemsize = PyArray_ITEMSIZE(__pyx_v_self);

  /* "numpy.pxd":236
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)             # <<<<<<<<<<<<<<
 * 
 *             cdef int t
 */
  __pyx_v_info->readonly = (!PyArray_ISWRITEABLE(__pyx_v_self));

  /* "numpy.pxd":239
 * 
 *             cdef int t
 *             cdef char* f = NULL             # <<<<<<<<<<<<<<
 *             cdef dtype descr = self.descr
 *             cdef list stack
 */
  __pyx_v_f = NULL;

  /* "numpy.pxd":240
 *             cdef int t
 *             cdef char* f = NULL
 *             cdef dtype descr = self.descr             # <<<<<<<<<<<<<<
 *             cdef list stack
 *             cdef int offset
 */
  __pyx_t_4 = ((PyObject *)__pyx_v_self->descr);
  __Pyx_INCREF(__pyx_t_4);
  __pyx_v_descr = ((PyArray_Descr *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "numpy.pxd":244
 *             cdef int offset
 * 
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)             # <<<<<<<<<<<<<<
 * 
 *             if not hasfields and not copy_shape:
 */
  __pyx_v_hasfields = PyDataType_HASFIELDS(__pyx_v_descr);

  /* "numpy.pxd":246
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)
 * 
 *             if not hasfields and not copy_shape:             # <<<<<<<<<<<<<<
 *                 # do not call releasebuffer
 *                 info.obj = None
 */
  __pyx_t_2 = (!__pyx_v_hasfields);
  if (__pyx_t_2) {
    __pyx_t_3 = (!__pyx_v_copy_shape);
    __pyx_t_1 = __pyx_t_3;
  } else {
    __pyx_t_1 = __pyx_t_2;
  }
  if (__pyx_t_1) {

    /* "numpy.pxd":248
 *             if not hasfields and not copy_shape:
 *                 # do not call releasebuffer
 *                 info.obj = None             # <<<<<<<<<<<<<<
 *             else:
 *                 # need to call releasebuffer
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj);
    __pyx_v_info->obj = Py_None;
    goto __pyx_L10;
  }
  /*else*/ {

    /* "numpy.pxd":251
 *             else:
 *                 # need to call releasebuffer
 *                 info.obj = self             # <<<<<<<<<<<<<<
 * 
 *             if not hasfields:
 */
    __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);
  }
  __pyx_L10:;

  /* "numpy.pxd":253
 *                 info.obj = self
 * 
 *             if not hasfields:             # <<<<<<<<<<<<<<
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 */
  __pyx_t_1 = (!__pyx_v_hasfields);
  if (__pyx_t_1) {

    /* "numpy.pxd":254
 * 
 *             if not hasfields:
 *                 t = descr.type_num             # <<<<<<<<<<<<<<
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 */
    __pyx_t_5 = __pyx_v_descr->type_num;
    __pyx_v_t = __pyx_t_5;

    /* "numpy.pxd":255
 *             if not hasfields:
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    __pyx_t_1 = (__pyx_v_descr->byteorder == '>');
    if (__pyx_t_1) {
      __pyx_t_2 = __pyx_v_little_endian;
    } else {
      __pyx_t_2 = __pyx_t_1;
    }
    if (!__pyx_t_2) {

      /* "numpy.pxd":256
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):             # <<<<<<<<<<<<<<
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 */
      __pyx_t_1 = (__pyx_v_descr->byteorder == '<');
      if (__pyx_t_1) {
        __pyx_t_3 = (!__pyx_v_little_endian);
        __pyx_t_7 = __pyx_t_3;
      } else {
        __pyx_t_7 = __pyx_t_1;
      }
      __pyx_t_1 = __pyx_t_7;
    } else {
      __pyx_t_1 = __pyx_t_2;
    }
    if (__pyx_t_1) {

      /* "numpy.pxd":257
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
      __pyx_t_4 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_75), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __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[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L12;
    }
    __pyx_L12:;

    /* "numpy.pxd":258
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_BYTE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__b;
      goto __pyx_L13;
    }

    /* "numpy.pxd":259
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_UBYTE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__B;
      goto __pyx_L13;
    }

    /* "numpy.pxd":260
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_SHORT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__h;
      goto __pyx_L13;
    }

    /* "numpy.pxd":261
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_USHORT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__H;
      goto __pyx_L13;
    }

    /* "numpy.pxd":262
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_INT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__i;
      goto __pyx_L13;
    }

    /* "numpy.pxd":263
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_UINT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__I;
      goto __pyx_L13;
    }

    /* "numpy.pxd":264
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_LONG);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__l;
      goto __pyx_L13;
    }

    /* "numpy.pxd":265
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_ULONG);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__L;
      goto __pyx_L13;
    }

    /* "numpy.pxd":266
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_LONGLONG);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__q;
      goto __pyx_L13;
    }

    /* "numpy.pxd":267
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_ULONGLONG);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__Q;
      goto __pyx_L13;
    }

    /* "numpy.pxd":268
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_FLOAT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__f;
      goto __pyx_L13;
    }

    /* "numpy.pxd":269
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_DOUBLE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__d;
      goto __pyx_L13;
    }

    /* "numpy.pxd":270
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_LONGDOUBLE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__g;
      goto __pyx_L13;
    }

    /* "numpy.pxd":271
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_CFLOAT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__Zf;
      goto __pyx_L13;
    }

    /* "numpy.pxd":272
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"
 */
    __pyx_t_1 = (__pyx_v_t == NPY_CDOUBLE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__Zd;
      goto __pyx_L13;
    }

    /* "numpy.pxd":273
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 */
    __pyx_t_1 = (__pyx_v_t == NPY_CLONGDOUBLE);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__Zg;
      goto __pyx_L13;
    }

    /* "numpy.pxd":274
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
    __pyx_t_1 = (__pyx_v_t == NPY_OBJECT);
    if (__pyx_t_1) {
      __pyx_v_f = __pyx_k__O;
      goto __pyx_L13;
    }
    /*else*/ {

      /* "numpy.pxd":276
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *                 info.format = f
 *                 return
 */
      __pyx_t_4 = PyInt_FromLong(__pyx_v_t); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_8 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_76), __pyx_t_4); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(((PyObject *)__pyx_t_8));
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_t_8));
      __Pyx_GIVEREF(((PyObject *)__pyx_t_8));
      __pyx_t_8 = 0;
      __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_4), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(((PyObject *)__pyx_t_4)); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_L13:;

    /* "numpy.pxd":277
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f             # <<<<<<<<<<<<<<
 *                 return
 *             else:
 */
    __pyx_v_info->format = __pyx_v_f;

    /* "numpy.pxd":278
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f
 *                 return             # <<<<<<<<<<<<<<
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 */
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L11;
  }
  /*else*/ {

    /* "numpy.pxd":280
 *                 return
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)             # <<<<<<<<<<<<<<
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0
 */
    __pyx_v_info->format = ((char *)malloc(255));

    /* "numpy.pxd":281
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 *                 info.format[0] = c'^' # Native data types, manual alignment             # <<<<<<<<<<<<<<
 *                 offset = 0
 *                 f = _util_dtypestring(descr, info.format + 1,
 */
    (__pyx_v_info->format[0]) = '^';

    /* "numpy.pxd":282
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0             # <<<<<<<<<<<<<<
 *                 f = _util_dtypestring(descr, info.format + 1,
 *                                       info.format + _buffer_format_string_len,
 */
    __pyx_v_offset = 0;

    /* "numpy.pxd":285
 *                 f = _util_dtypestring(descr, info.format + 1,
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)             # <<<<<<<<<<<<<<
 *                 f[0] = c'\0' # Terminate format string
 * 
 */
    __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 255), (&__pyx_v_offset)); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 283; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_f = __pyx_t_9;

    /* "numpy.pxd":286
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)
 *                 f[0] = c'\0' # Terminate format string             # <<<<<<<<<<<<<<
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 */
    (__pyx_v_f[0]) = '\x00';
  }
  __pyx_L11:;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("numpy.ndarray.__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((PyObject *)__pyx_v_descr);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/
static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
  __pyx_pf_5numpy_7ndarray_2__releasebuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info));
  __Pyx_RefNannyFinishContext();
}

/* "numpy.pxd":288
 *                 f[0] = c'\0' # Terminate format string
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 */

static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__releasebuffer__", 0);

  /* "numpy.pxd":289
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_t_1 = PyArray_HASFIELDS(__pyx_v_self);
  if (__pyx_t_1) {

    /* "numpy.pxd":290
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)             # <<<<<<<<<<<<<<
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 stdlib.free(info.strides)
 */
    free(__pyx_v_info->format);
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "numpy.pxd":291
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.strides)
 *                 # info.shape was stored after info.strides in the same block
 */
  __pyx_t_1 = ((sizeof(npy_intp)) != (sizeof(Py_ssize_t)));
  if (__pyx_t_1) {

    /* "numpy.pxd":292
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 stdlib.free(info.strides)             # <<<<<<<<<<<<<<
 *                 # info.shape was stored after info.strides in the same block
 * 
 */
    free(__pyx_v_info->strides);
    goto __pyx_L4;
  }
  __pyx_L4:;

  __Pyx_RefNannyFinishContext();
}

/* "numpy.pxd":768
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__pyx_v_a) {
  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_RefNannySetupContext("PyArray_MultiIterNew1", 0);

  /* "numpy.pxd":769
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 *     return PyArray_MultiIterNew(1, <void*>a)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew1", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":771
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__pyx_v_a, PyObject *__pyx_v_b) {
  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_RefNannySetupContext("PyArray_MultiIterNew2", 0);

  /* "numpy.pxd":772
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew2", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":774
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) {
  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_RefNannySetupContext("PyArray_MultiIterNew3", 0);

  /* "numpy.pxd":775
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":777
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d) {
  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_RefNannySetupContext("PyArray_MultiIterNew4", 0);

  /* "numpy.pxd":778
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 778; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew4", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":780
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d, PyObject *__pyx_v_e) {
  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_RefNannySetupContext("PyArray_MultiIterNew5", 0);

  /* "numpy.pxd":781
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)             # <<<<<<<<<<<<<<
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 781; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew5", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":783
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:             # <<<<<<<<<<<<<<
 *     # Recursive utility function used in __getbuffer__ to get format
 *     # string. The new location in the format string is returned.
 */

static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_descr, char *__pyx_v_f, char *__pyx_v_end, int *__pyx_v_offset) {
  PyArray_Descr *__pyx_v_child = 0;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_childname = NULL;
  PyObject *__pyx_v_new_offset = NULL;
  PyObject *__pyx_v_t = NULL;
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *(*__pyx_t_6)(PyObject *);
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  long __pyx_t_11;
  char *__pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_util_dtypestring", 0);

  /* "numpy.pxd":790
 *     cdef int delta_offset
 *     cdef tuple i
 *     cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 *     cdef tuple fields
 */
  __pyx_v_endian_detector = 1;

  /* "numpy.pxd":791
 *     cdef tuple i
 *     cdef int endian_detector = 1
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 *     cdef tuple fields
 * 
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "numpy.pxd":794
 *     cdef tuple fields
 * 
 *     for childname in descr.names:             # <<<<<<<<<<<<<<
 *         fields = descr.fields[childname]
 *         child, new_offset = fields
 */
  if (unlikely(((PyObject *)__pyx_v_descr->names) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_1 = ((PyObject *)__pyx_v_descr->names); __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #endif
    __Pyx_XDECREF(__pyx_v_childname);
    __pyx_v_childname = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "numpy.pxd":795
 * 
 *     for childname in descr.names:
 *         fields = descr.fields[childname]             # <<<<<<<<<<<<<<
 *         child, new_offset = fields
 * 
 */
    __pyx_t_3 = PyObject_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (!__pyx_t_3) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected tuple, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF(((PyObject *)__pyx_v_fields));
    __pyx_v_fields = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "numpy.pxd":796
 *     for childname in descr.names:
 *         fields = descr.fields[childname]
 *         child, new_offset = fields             # <<<<<<<<<<<<<<
 * 
 *         if (end - f) - (new_offset - offset[0]) < 15:
 */
    if (likely(PyTuple_CheckExact(((PyObject *)__pyx_v_fields)))) {
      PyObject* sequence = ((PyObject *)__pyx_v_fields);
      #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[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      #endif
    } else if (1) {
      __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else
    {
      Py_ssize_t index = -1;
      __pyx_t_5 = PyObject_GetIter(((PyObject *)__pyx_v_fields)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext;
      index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_6 = NULL;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      goto __pyx_L6_unpacking_done;
      __pyx_L5_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_L6_unpacking_done:;
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF(((PyObject *)__pyx_v_child));
    __pyx_v_child = ((PyArray_Descr *)__pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_v_new_offset);
    __pyx_v_new_offset = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "numpy.pxd":798
 *         child, new_offset = fields
 * 
 *         if (end - f) - (new_offset - offset[0]) < 15:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 */
    __pyx_t_4 = PyInt_FromLong((__pyx_v_end - __pyx_v_f)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_3); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __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_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_int_15, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_7) {

      /* "numpy.pxd":799
 * 
 *         if (end - f) - (new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 */
      __pyx_t_5 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_78), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L7;
    }
    __pyx_L7:;

    /* "numpy.pxd":801
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    __pyx_t_7 = (__pyx_v_child->byteorder == '>');
    if (__pyx_t_7) {
      __pyx_t_8 = __pyx_v_little_endian;
    } else {
      __pyx_t_8 = __pyx_t_7;
    }
    if (!__pyx_t_8) {

      /* "numpy.pxd":802
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):             # <<<<<<<<<<<<<<
 *             raise ValueError(u"Non-native byte order not supported")
 *             # One could encode it in the format string and have Cython
 */
      __pyx_t_7 = (__pyx_v_child->byteorder == '<');
      if (__pyx_t_7) {
        __pyx_t_9 = (!__pyx_v_little_endian);
        __pyx_t_10 = __pyx_t_9;
      } else {
        __pyx_t_10 = __pyx_t_7;
      }
      __pyx_t_7 = __pyx_t_10;
    } else {
      __pyx_t_7 = __pyx_t_8;
    }
    if (__pyx_t_7) {

      /* "numpy.pxd":803
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
      __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_79), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_Raise(__pyx_t_5, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      goto __pyx_L8;
    }
    __pyx_L8:;

    /* "numpy.pxd":813
 * 
 *         # Output padding bytes
 *         while offset[0] < new_offset:             # <<<<<<<<<<<<<<
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 */
    while (1) {
      __pyx_t_5 = PyInt_FromLong((__pyx_v_offset[0])); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_v_new_offset, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!__pyx_t_7) break;

      /* "numpy.pxd":814
 *         # Output padding bytes
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte             # <<<<<<<<<<<<<<
 *             f += 1
 *             offset[0] += 1
 */
      (__pyx_v_f[0]) = 120;

      /* "numpy.pxd":815
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte
 *             f += 1             # <<<<<<<<<<<<<<
 *             offset[0] += 1
 * 
 */
      __pyx_v_f = (__pyx_v_f + 1);

      /* "numpy.pxd":816
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 *             offset[0] += 1             # <<<<<<<<<<<<<<
 * 
 *         offset[0] += child.itemsize
 */
      __pyx_t_11 = 0;
      (__pyx_v_offset[__pyx_t_11]) = ((__pyx_v_offset[__pyx_t_11]) + 1);
    }

    /* "numpy.pxd":818
 *             offset[0] += 1
 * 
 *         offset[0] += child.itemsize             # <<<<<<<<<<<<<<
 * 
 *         if not PyDataType_HASFIELDS(child):
 */
    __pyx_t_11 = 0;
    (__pyx_v_offset[__pyx_t_11]) = ((__pyx_v_offset[__pyx_t_11]) + __pyx_v_child->elsize);

    /* "numpy.pxd":820
 *         offset[0] += child.itemsize
 * 
 *         if not PyDataType_HASFIELDS(child):             # <<<<<<<<<<<<<<
 *             t = child.type_num
 *             if end - f < 5:
 */
    __pyx_t_7 = (!PyDataType_HASFIELDS(__pyx_v_child));
    if (__pyx_t_7) {

      /* "numpy.pxd":821
 * 
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num             # <<<<<<<<<<<<<<
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")
 */
      __pyx_t_3 = PyInt_FromLong(__pyx_v_child->type_num); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_v_t);
      __pyx_v_t = __pyx_t_3;
      __pyx_t_3 = 0;

      /* "numpy.pxd":822
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num
 *             if end - f < 5:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(u"Format string allocated too short.")
 * 
 */
      __pyx_t_7 = ((__pyx_v_end - __pyx_v_f) < 5);
      if (__pyx_t_7) {

        /* "numpy.pxd":823
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
        __pyx_t_3 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_k_tuple_81), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __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[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        goto __pyx_L12;
      }
      __pyx_L12:;

      /* "numpy.pxd":826
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_BYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 98;
        goto __pyx_L13;
      }

      /* "numpy.pxd":827
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"             # <<<<<<<<<<<<<<
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 */
      __pyx_t_5 = PyInt_FromLong(NPY_UBYTE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 66;
        goto __pyx_L13;
      }

      /* "numpy.pxd":828
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"             # <<<<<<<<<<<<<<
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_SHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 104;
        goto __pyx_L13;
      }

      /* "numpy.pxd":829
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"             # <<<<<<<<<<<<<<
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 */
      __pyx_t_5 = PyInt_FromLong(NPY_USHORT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 72;
        goto __pyx_L13;
      }

      /* "numpy.pxd":830
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_INT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 105;
        goto __pyx_L13;
      }

      /* "numpy.pxd":831
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 */
      __pyx_t_5 = PyInt_FromLong(NPY_UINT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 73;
        goto __pyx_L13;
      }

      /* "numpy.pxd":832
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_LONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 108;
        goto __pyx_L13;
      }

      /* "numpy.pxd":833
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 */
      __pyx_t_5 = PyInt_FromLong(NPY_ULONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 76;
        goto __pyx_L13;
      }

      /* "numpy.pxd":834
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_LONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 113;
        goto __pyx_L13;
      }

      /* "numpy.pxd":835
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 */
      __pyx_t_5 = PyInt_FromLong(NPY_ULONGLONG); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 81;
        goto __pyx_L13;
      }

      /* "numpy.pxd":836
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"             # <<<<<<<<<<<<<<
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_FLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 102;
        goto __pyx_L13;
      }

      /* "numpy.pxd":837
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 */
      __pyx_t_5 = PyInt_FromLong(NPY_DOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 100;
        goto __pyx_L13;
      }

      /* "numpy.pxd":838
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"             # <<<<<<<<<<<<<<
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 */
      __pyx_t_3 = PyInt_FromLong(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 103;
        goto __pyx_L13;
      }

      /* "numpy.pxd":839
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf             # <<<<<<<<<<<<<<
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 */
      __pyx_t_5 = PyInt_FromLong(NPY_CFLOAT); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 102;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L13;
      }

      /* "numpy.pxd":840
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd             # <<<<<<<<<<<<<<
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 */
      __pyx_t_3 = PyInt_FromLong(NPY_CDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 100;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L13;
      }

      /* "numpy.pxd":841
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg             # <<<<<<<<<<<<<<
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 */
      __pyx_t_5 = PyInt_FromLong(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 103;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L13;
      }

      /* "numpy.pxd":842
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
      __pyx_t_3 = PyInt_FromLong(NPY_OBJECT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_5 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_7) {
        (__pyx_v_f[0]) = 79;
        goto __pyx_L13;
      }
      /*else*/ {

        /* "numpy.pxd":844
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *             f += 1
 *         else:
 */
        __pyx_t_5 = PyNumber_Remainder(((PyObject *)__pyx_kp_u_76), __pyx_v_t); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(((PyObject *)__pyx_t_5));
        __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_5));
        __Pyx_GIVEREF(((PyObject *)__pyx_t_5));
        __pyx_t_5 = 0;
        __pyx_t_5 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(((PyObject *)__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[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_L13:;

      /* "numpy.pxd":845
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *             f += 1             # <<<<<<<<<<<<<<
 *         else:
 *             # Cython ignores struct boundary information ("T{...}"),
 */
      __pyx_v_f = (__pyx_v_f + 1);
      goto __pyx_L11;
    }
    /*else*/ {

      /* "numpy.pxd":849
 *             # Cython ignores struct boundary information ("T{...}"),
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)             # <<<<<<<<<<<<<<
 *     return f
 * 
 */
      __pyx_t_12 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_12 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_f = __pyx_t_12;
    }
    __pyx_L11:;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "numpy.pxd":850
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)
 *     return f             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_f;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("numpy._util_dtypestring", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_child);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_childname);
  __Pyx_XDECREF(__pyx_v_new_offset);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "numpy.pxd":965
 * 
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *      cdef PyObject* baseptr
 *      if base is None:
 */

static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) {
  PyObject *__pyx_v_baseptr;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("set_array_base", 0);

  /* "numpy.pxd":967
 * cdef inline void set_array_base(ndarray arr, object base):
 *      cdef PyObject* baseptr
 *      if base is None:             # <<<<<<<<<<<<<<
 *          baseptr = NULL
 *      else:
 */
  __pyx_t_1 = (__pyx_v_base == Py_None);
  if (__pyx_t_1) {

    /* "numpy.pxd":968
 *      cdef PyObject* baseptr
 *      if base is None:
 *          baseptr = NULL             # <<<<<<<<<<<<<<
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 */
    __pyx_v_baseptr = NULL;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "numpy.pxd":970
 *          baseptr = NULL
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!             # <<<<<<<<<<<<<<
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 */
    Py_INCREF(__pyx_v_base);

    /* "numpy.pxd":971
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base             # <<<<<<<<<<<<<<
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr
 */
    __pyx_v_baseptr = ((PyObject *)__pyx_v_base);
  }
  __pyx_L3:;

  /* "numpy.pxd":972
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)             # <<<<<<<<<<<<<<
 *      arr.base = baseptr
 * 
 */
  Py_XDECREF(__pyx_v_arr->base);

  /* "numpy.pxd":973
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr             # <<<<<<<<<<<<<<
 * 
 * cdef inline object get_array_base(ndarray arr):
 */
  __pyx_v_arr->base = __pyx_v_baseptr;

  __Pyx_RefNannyFinishContext();
}

/* "numpy.pxd":975
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("get_array_base", 0);

  /* "numpy.pxd":976
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     else:
 */
  __pyx_t_1 = (__pyx_v_arr->base == NULL);
  if (__pyx_t_1) {

    /* "numpy.pxd":977
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:
 *         return None             # <<<<<<<<<<<<<<
 *     else:
 *         return <object>arr.base
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  /*else*/ {

    /* "numpy.pxd":979
 *         return None
 *     else:
 *         return <object>arr.base             # <<<<<<<<<<<<<<
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_arr->base));
    __pyx_r = ((PyObject *)__pyx_v_arr->base);
    goto __pyx_L0;
  }
  __pyx_L3:;

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

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct__stat_coverage(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct__stat_coverage(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct__stat_coverage(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct__stat_coverage(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct__stat_coverage[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct__stat_coverage = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct__stat_coverage = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct__stat_coverage = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct__stat_coverage = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct__stat_coverage = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct__stat_coverage"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct__stat_coverage), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct__stat_coverage, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct__stat_coverage, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct__stat_coverage, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct__stat_coverage, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct__stat_coverage, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct__stat_coverage, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct__stat_coverage, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct__stat_coverage, /*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_10pysamstats___pyx_scope_struct__stat_coverage, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_1_stat_coverage_strand(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_1_stat_coverage_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_1_stat_coverage_strand(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_1_stat_coverage_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_1_stat_coverage_strand[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1_stat_coverage_strand = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1_stat_coverage_strand = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1_stat_coverage_strand = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1_stat_coverage_strand = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_1_stat_coverage_strand = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_1_stat_coverage_strand"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_1_stat_coverage_strand), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_1_stat_coverage_strand, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_1_stat_coverage_strand, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_1_stat_coverage_strand, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_1_stat_coverage_strand, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_1_stat_coverage_strand, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_1_stat_coverage_strand, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_1_stat_coverage_strand, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_1_stat_coverage_strand, /*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_10pysamstats___pyx_scope_struct_1_stat_coverage_strand, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_2_stat_coverage_ext(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_2_stat_coverage_ext(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_2_stat_coverage_ext(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_2_stat_coverage_ext(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_2_stat_coverage_ext[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_stat_coverage_ext = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_stat_coverage_ext = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_stat_coverage_ext = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_stat_coverage_ext = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_2_stat_coverage_ext = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_2_stat_coverage_ext"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_2_stat_coverage_ext), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_2_stat_coverage_ext, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_2_stat_coverage_ext, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_2_stat_coverage_ext, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_2_stat_coverage_ext, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_2_stat_coverage_ext, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_2_stat_coverage_ext, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_2_stat_coverage_ext, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_2_stat_coverage_ext, /*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_10pysamstats___pyx_scope_struct_2_stat_coverage_ext, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_stat_coverage_ext_strand = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_stat_coverage_ext_strand = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_stat_coverage_ext_strand = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_stat_coverage_ext_strand = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_3_stat_coverage_ext_strand"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_3_stat_coverage_ext_strand, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_3_stat_coverage_ext_strand, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_3_stat_coverage_ext_strand, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_3_stat_coverage_ext_strand, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand, /*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_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_4_stat_variation(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_fafile = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_4_stat_variation(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_fafile);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_4_stat_variation(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_fafile) {
    e = (*v)(((PyObject*)p->__pyx_v_fafile), a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_4_stat_variation(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_fafile);
  p->__pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_4_stat_variation[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_stat_variation = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_stat_variation = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_stat_variation = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_stat_variation = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_4_stat_variation = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_4_stat_variation"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_4_stat_variation), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_4_stat_variation, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_4_stat_variation, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_4_stat_variation, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_4_stat_variation, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_4_stat_variation, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_4_stat_variation, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_4_stat_variation, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_4_stat_variation, /*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_10pysamstats___pyx_scope_struct_4_stat_variation, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_5_stat_variation_strand(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_fafile = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_5_stat_variation_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_fafile);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_5_stat_variation_strand(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_fafile) {
    e = (*v)(((PyObject*)p->__pyx_v_fafile), a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_5_stat_variation_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_fafile);
  p->__pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_5_stat_variation_strand[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5_stat_variation_strand = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5_stat_variation_strand = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5_stat_variation_strand = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5_stat_variation_strand = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_5_stat_variation_strand = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_5_stat_variation_strand"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_5_stat_variation_strand), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_5_stat_variation_strand, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_5_stat_variation_strand, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_5_stat_variation_strand, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_5_stat_variation_strand, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_5_stat_variation_strand, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_5_stat_variation_strand, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_5_stat_variation_strand, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_5_stat_variation_strand, /*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_10pysamstats___pyx_scope_struct_5_stat_variation_strand, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_6_stat_tlen(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_6_stat_tlen(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_6_stat_tlen(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_6_stat_tlen(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_6_stat_tlen[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6_stat_tlen = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6_stat_tlen = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_6_stat_tlen = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6_stat_tlen = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_6_stat_tlen = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_6_stat_tlen"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_6_stat_tlen), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_6_stat_tlen, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_6_stat_tlen, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_6_stat_tlen, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_6_stat_tlen, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_6_stat_tlen, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_6_stat_tlen, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_6_stat_tlen, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_6_stat_tlen, /*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_10pysamstats___pyx_scope_struct_6_stat_tlen, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_7_stat_tlen_strand(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_7_stat_tlen_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_7_stat_tlen_strand(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_7_stat_tlen_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_7_stat_tlen_strand[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7_stat_tlen_strand = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7_stat_tlen_strand = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_7_stat_tlen_strand = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7_stat_tlen_strand = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_7_stat_tlen_strand = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_7_stat_tlen_strand"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_7_stat_tlen_strand), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_7_stat_tlen_strand, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_7_stat_tlen_strand, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_7_stat_tlen_strand, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_7_stat_tlen_strand, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_7_stat_tlen_strand, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_7_stat_tlen_strand, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_7_stat_tlen_strand, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_7_stat_tlen_strand, /*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_10pysamstats___pyx_scope_struct_7_stat_tlen_strand, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_8_stat_mapq(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_8_stat_mapq(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_8_stat_mapq(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_8_stat_mapq(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_8_stat_mapq[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8_stat_mapq = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8_stat_mapq = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8_stat_mapq = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8_stat_mapq = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_8_stat_mapq = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_8_stat_mapq"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_8_stat_mapq), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_8_stat_mapq, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_8_stat_mapq, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_8_stat_mapq, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_8_stat_mapq, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_8_stat_mapq, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_8_stat_mapq, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_8_stat_mapq, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_8_stat_mapq, /*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_10pysamstats___pyx_scope_struct_8_stat_mapq, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_9_stat_mapq_strand(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_9_stat_mapq_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_9_stat_mapq_strand(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_9_stat_mapq_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_9_stat_mapq_strand[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_9_stat_mapq_strand = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_9_stat_mapq_strand = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_9_stat_mapq_strand = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_9_stat_mapq_strand = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_9_stat_mapq_strand = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_9_stat_mapq_strand"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_9_stat_mapq_strand), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_9_stat_mapq_strand, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_9_stat_mapq_strand, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_9_stat_mapq_strand, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_9_stat_mapq_strand, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_9_stat_mapq_strand, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_9_stat_mapq_strand, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_9_stat_mapq_strand, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_9_stat_mapq_strand, /*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_10pysamstats___pyx_scope_struct_9_stat_mapq_strand, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_10_stat_baseq(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_10_stat_baseq(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_10_stat_baseq(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_10_stat_baseq(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_10_stat_baseq[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_10_stat_baseq = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_10_stat_baseq = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_10_stat_baseq = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_10_stat_baseq = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_10_stat_baseq = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_10_stat_baseq"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_10_stat_baseq), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_10_stat_baseq, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_10_stat_baseq, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_10_stat_baseq, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_10_stat_baseq, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_10_stat_baseq, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_10_stat_baseq, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_10_stat_baseq, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_10_stat_baseq, /*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_10pysamstats___pyx_scope_struct_10_stat_baseq, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_11_stat_baseq_strand(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_11_stat_baseq_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_11_stat_baseq_strand(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_11_stat_baseq_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_11_stat_baseq_strand[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_11_stat_baseq_strand = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_11_stat_baseq_strand = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_11_stat_baseq_strand = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_11_stat_baseq_strand = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_11_stat_baseq_strand = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_11_stat_baseq_strand"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_11_stat_baseq_strand), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_11_stat_baseq_strand, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_11_stat_baseq_strand, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_11_stat_baseq_strand, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_11_stat_baseq_strand, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_11_stat_baseq_strand, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_11_stat_baseq_strand, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_11_stat_baseq_strand, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_11_stat_baseq_strand, /*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_10pysamstats___pyx_scope_struct_11_stat_baseq_strand, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_12_stat_baseq_ext(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_fafile = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_12_stat_baseq_ext(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_fafile);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_12_stat_baseq_ext(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_fafile) {
    e = (*v)(((PyObject*)p->__pyx_v_fafile), a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_12_stat_baseq_ext(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_fafile);
  p->__pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_12_stat_baseq_ext[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_12_stat_baseq_ext = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_12_stat_baseq_ext = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_12_stat_baseq_ext = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_12_stat_baseq_ext = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_12_stat_baseq_ext = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_12_stat_baseq_ext"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_12_stat_baseq_ext), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_12_stat_baseq_ext, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_12_stat_baseq_ext, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_12_stat_baseq_ext, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_12_stat_baseq_ext, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_12_stat_baseq_ext, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_12_stat_baseq_ext, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_12_stat_baseq_ext, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_12_stat_baseq_ext, /*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_10pysamstats___pyx_scope_struct_12_stat_baseq_ext, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_fafile = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_fafile);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_fafile) {
    e = (*v)(((PyObject*)p->__pyx_v_fafile), a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_fafile);
  p->__pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_13_stat_baseq_ext_strand = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_13_stat_baseq_ext_strand = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_13_stat_baseq_ext_strand = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_13_stat_baseq_ext_strand = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_13_stat_baseq_ext_strand"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_13_stat_baseq_ext_strand, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_13_stat_baseq_ext_strand, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_13_stat_baseq_ext_strand, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_13_stat_baseq_ext_strand, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand, /*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_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_14_stat_coverage_normed(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *)o);
  p->__pyx_v_a = 0;
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_dp = 0;
  p->__pyx_v_dp_mean = 0;
  p->__pyx_v_dp_median = 0;
  p->__pyx_v_dp_normed_mean = 0;
  p->__pyx_v_dp_normed_median = 0;
  p->__pyx_v_dp_percentile = 0;
  p->__pyx_v_dp_percentiles = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_genexpr = 0;
  p->__pyx_v_it = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_pos = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_14_stat_coverage_normed(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_a);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_dp);
  Py_CLEAR(p->__pyx_v_dp_mean);
  Py_CLEAR(p->__pyx_v_dp_median);
  Py_CLEAR(p->__pyx_v_dp_normed_mean);
  Py_CLEAR(p->__pyx_v_dp_normed_median);
  Py_CLEAR(p->__pyx_v_dp_percentile);
  Py_CLEAR(p->__pyx_v_dp_percentiles);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_genexpr);
  Py_CLEAR(p->__pyx_v_it);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_pos);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_14_stat_coverage_normed(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *)o;
  if (p->__pyx_v_a) {
    e = (*v)(p->__pyx_v_a, a); if (e) return e;
  }
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_dp) {
    e = (*v)(p->__pyx_v_dp, a); if (e) return e;
  }
  if (p->__pyx_v_dp_mean) {
    e = (*v)(p->__pyx_v_dp_mean, a); if (e) return e;
  }
  if (p->__pyx_v_dp_median) {
    e = (*v)(p->__pyx_v_dp_median, a); if (e) return e;
  }
  if (p->__pyx_v_dp_normed_mean) {
    e = (*v)(p->__pyx_v_dp_normed_mean, a); if (e) return e;
  }
  if (p->__pyx_v_dp_normed_median) {
    e = (*v)(p->__pyx_v_dp_normed_median, a); if (e) return e;
  }
  if (p->__pyx_v_dp_percentile) {
    e = (*v)(p->__pyx_v_dp_percentile, a); if (e) return e;
  }
  if (p->__pyx_v_dp_percentiles) {
    e = (*v)(p->__pyx_v_dp_percentiles, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_genexpr) {
    e = (*v)(p->__pyx_v_genexpr, a); if (e) return e;
  }
  if (p->__pyx_v_it) {
    e = (*v)(p->__pyx_v_it, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_pos) {
    e = (*v)(p->__pyx_v_pos, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_14_stat_coverage_normed(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_a);
  p->__pyx_v_a = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp);
  p->__pyx_v_dp = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_mean);
  p->__pyx_v_dp_mean = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_median);
  p->__pyx_v_dp_median = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_normed_mean);
  p->__pyx_v_dp_normed_mean = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_normed_median);
  p->__pyx_v_dp_normed_median = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_percentile);
  p->__pyx_v_dp_percentile = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_percentiles);
  p->__pyx_v_dp_percentiles = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_genexpr);
  p->__pyx_v_genexpr = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_it);
  p->__pyx_v_it = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_pos);
  p->__pyx_v_pos = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_14_stat_coverage_normed[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_14_stat_coverage_normed = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_14_stat_coverage_normed = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_14_stat_coverage_normed = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_14_stat_coverage_normed = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_14_stat_coverage_normed = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_14_stat_coverage_normed"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_14_stat_coverage_normed, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_14_stat_coverage_normed, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_14_stat_coverage_normed, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_14_stat_coverage_normed, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_14_stat_coverage_normed, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_14_stat_coverage_normed, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_14_stat_coverage_normed, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_14_stat_coverage_normed, /*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_10pysamstats___pyx_scope_struct_14_stat_coverage_normed, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_15_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *)o);
  p->__pyx_outer_scope = 0;
  p->__pyx_v_col = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_15_genexpr(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_15_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *)o;
  if (p->__pyx_outer_scope) {
    e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_15_genexpr(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_outer_scope);
  p->__pyx_outer_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_14_stat_coverage_normed *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_15_genexpr[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_15_genexpr = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_15_genexpr = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_15_genexpr = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_15_genexpr = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_15_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_15_genexpr"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_15_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_15_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*/
  &__pyx_tp_as_number___pyx_scope_struct_15_genexpr, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_15_genexpr, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_15_genexpr, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_15_genexpr, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_15_genexpr, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_15_genexpr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_15_genexpr, /*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_10pysamstats___pyx_scope_struct_15_genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_16_stat_coverage_gc(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *)o);
  p->__pyx_v_chrom = 0;
  p->__pyx_v_col = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_fafile = 0;
  p->__pyx_v_gc_percent = 0;
  p->__pyx_v_gc_window_length = 0;
  p->__pyx_v_gc_window_offset = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_rec = 0;
  p->__pyx_v_ref_window = 0;
  p->__pyx_v_ref_window_end = 0;
  p->__pyx_v_ref_window_start = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_16_stat_coverage_gc(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_col);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_fafile);
  Py_CLEAR(p->__pyx_v_gc_percent);
  Py_CLEAR(p->__pyx_v_gc_window_length);
  Py_CLEAR(p->__pyx_v_gc_window_offset);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_rec);
  Py_CLEAR(p->__pyx_v_ref_window);
  Py_CLEAR(p->__pyx_v_ref_window_end);
  Py_CLEAR(p->__pyx_v_ref_window_start);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_16_stat_coverage_gc(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *)o;
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_col) {
    e = (*v)(p->__pyx_v_col, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_fafile) {
    e = (*v)(((PyObject*)p->__pyx_v_fafile), a); if (e) return e;
  }
  if (p->__pyx_v_gc_percent) {
    e = (*v)(p->__pyx_v_gc_percent, a); if (e) return e;
  }
  if (p->__pyx_v_gc_window_length) {
    e = (*v)(p->__pyx_v_gc_window_length, a); if (e) return e;
  }
  if (p->__pyx_v_gc_window_offset) {
    e = (*v)(p->__pyx_v_gc_window_offset, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_rec) {
    e = (*v)(p->__pyx_v_rec, a); if (e) return e;
  }
  if (p->__pyx_v_ref_window) {
    e = (*v)(p->__pyx_v_ref_window, a); if (e) return e;
  }
  if (p->__pyx_v_ref_window_end) {
    e = (*v)(p->__pyx_v_ref_window_end, a); if (e) return e;
  }
  if (p->__pyx_v_ref_window_start) {
    e = (*v)(p->__pyx_v_ref_window_start, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_16_stat_coverage_gc(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_col);
  p->__pyx_v_col = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_fafile);
  p->__pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_gc_percent);
  p->__pyx_v_gc_percent = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_gc_window_length);
  p->__pyx_v_gc_window_length = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_gc_window_offset);
  p->__pyx_v_gc_window_offset = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_rec);
  p->__pyx_v_rec = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_ref_window);
  p->__pyx_v_ref_window = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_ref_window_end);
  p->__pyx_v_ref_window_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_ref_window_start);
  p->__pyx_v_ref_window_start = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_16_stat_coverage_gc[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_16_stat_coverage_gc = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_16_stat_coverage_gc = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_16_stat_coverage_gc = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_16_stat_coverage_gc = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_16_stat_coverage_gc = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_16_stat_coverage_gc"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_16_stat_coverage_gc), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_16_stat_coverage_gc, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_16_stat_coverage_gc, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_16_stat_coverage_gc, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_16_stat_coverage_gc, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_16_stat_coverage_gc, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_16_stat_coverage_gc, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_16_stat_coverage_gc, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_16_stat_coverage_gc, /*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_10pysamstats___pyx_scope_struct_16_stat_coverage_gc, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *)o);
  p->__pyx_v_a = 0;
  p->__pyx_v_b = 0;
  p->__pyx_v_chrom = 0;
  p->__pyx_v_dp = 0;
  p->__pyx_v_dp_mean = 0;
  p->__pyx_v_dp_mean_bygc = 0;
  p->__pyx_v_dp_median = 0;
  p->__pyx_v_dp_median_bygc = 0;
  p->__pyx_v_dp_normed_mean = 0;
  p->__pyx_v_dp_normed_mean_bygc = 0;
  p->__pyx_v_dp_normed_median = 0;
  p->__pyx_v_dp_normed_median_bygc = 0;
  p->__pyx_v_dp_percentile = 0;
  p->__pyx_v_dp_percentile_bygc = 0;
  p->__pyx_v_dp_percentiles = 0;
  p->__pyx_v_dp_percentiles_bygc = 0;
  p->__pyx_v_end = 0;
  p->__pyx_v_fafile = 0;
  p->__pyx_v_flt = 0;
  p->__pyx_v_gc = 0;
  p->__pyx_v_genexpr = 0;
  p->__pyx_v_it = 0;
  p->__pyx_v_kwargs = 0;
  p->__pyx_v_one_based = 0;
  p->__pyx_v_rec = 0;
  p->__pyx_v_recs = 0;
  p->__pyx_v_samfile = 0;
  p->__pyx_v_start = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_v_a);
  Py_CLEAR(p->__pyx_v_b);
  Py_CLEAR(p->__pyx_v_chrom);
  Py_CLEAR(p->__pyx_v_dp);
  Py_CLEAR(p->__pyx_v_dp_mean);
  Py_CLEAR(p->__pyx_v_dp_mean_bygc);
  Py_CLEAR(p->__pyx_v_dp_median);
  Py_CLEAR(p->__pyx_v_dp_median_bygc);
  Py_CLEAR(p->__pyx_v_dp_normed_mean);
  Py_CLEAR(p->__pyx_v_dp_normed_mean_bygc);
  Py_CLEAR(p->__pyx_v_dp_normed_median);
  Py_CLEAR(p->__pyx_v_dp_normed_median_bygc);
  Py_CLEAR(p->__pyx_v_dp_percentile);
  Py_CLEAR(p->__pyx_v_dp_percentile_bygc);
  Py_CLEAR(p->__pyx_v_dp_percentiles);
  Py_CLEAR(p->__pyx_v_dp_percentiles_bygc);
  Py_CLEAR(p->__pyx_v_end);
  Py_CLEAR(p->__pyx_v_fafile);
  Py_CLEAR(p->__pyx_v_flt);
  Py_CLEAR(p->__pyx_v_gc);
  Py_CLEAR(p->__pyx_v_genexpr);
  Py_CLEAR(p->__pyx_v_it);
  Py_CLEAR(p->__pyx_v_kwargs);
  Py_CLEAR(p->__pyx_v_one_based);
  Py_CLEAR(p->__pyx_v_rec);
  Py_CLEAR(p->__pyx_v_recs);
  Py_CLEAR(p->__pyx_v_samfile);
  Py_CLEAR(p->__pyx_v_start);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *)o;
  if (p->__pyx_v_a) {
    e = (*v)(p->__pyx_v_a, a); if (e) return e;
  }
  if (p->__pyx_v_b) {
    e = (*v)(p->__pyx_v_b, a); if (e) return e;
  }
  if (p->__pyx_v_chrom) {
    e = (*v)(p->__pyx_v_chrom, a); if (e) return e;
  }
  if (p->__pyx_v_dp) {
    e = (*v)(p->__pyx_v_dp, a); if (e) return e;
  }
  if (p->__pyx_v_dp_mean) {
    e = (*v)(p->__pyx_v_dp_mean, a); if (e) return e;
  }
  if (p->__pyx_v_dp_mean_bygc) {
    e = (*v)(p->__pyx_v_dp_mean_bygc, a); if (e) return e;
  }
  if (p->__pyx_v_dp_median) {
    e = (*v)(p->__pyx_v_dp_median, a); if (e) return e;
  }
  if (p->__pyx_v_dp_median_bygc) {
    e = (*v)(p->__pyx_v_dp_median_bygc, a); if (e) return e;
  }
  if (p->__pyx_v_dp_normed_mean) {
    e = (*v)(p->__pyx_v_dp_normed_mean, a); if (e) return e;
  }
  if (p->__pyx_v_dp_normed_mean_bygc) {
    e = (*v)(p->__pyx_v_dp_normed_mean_bygc, a); if (e) return e;
  }
  if (p->__pyx_v_dp_normed_median) {
    e = (*v)(p->__pyx_v_dp_normed_median, a); if (e) return e;
  }
  if (p->__pyx_v_dp_normed_median_bygc) {
    e = (*v)(p->__pyx_v_dp_normed_median_bygc, a); if (e) return e;
  }
  if (p->__pyx_v_dp_percentile) {
    e = (*v)(p->__pyx_v_dp_percentile, a); if (e) return e;
  }
  if (p->__pyx_v_dp_percentile_bygc) {
    e = (*v)(p->__pyx_v_dp_percentile_bygc, a); if (e) return e;
  }
  if (p->__pyx_v_dp_percentiles) {
    e = (*v)(p->__pyx_v_dp_percentiles, a); if (e) return e;
  }
  if (p->__pyx_v_dp_percentiles_bygc) {
    e = (*v)(p->__pyx_v_dp_percentiles_bygc, a); if (e) return e;
  }
  if (p->__pyx_v_end) {
    e = (*v)(p->__pyx_v_end, a); if (e) return e;
  }
  if (p->__pyx_v_fafile) {
    e = (*v)(((PyObject*)p->__pyx_v_fafile), a); if (e) return e;
  }
  if (p->__pyx_v_flt) {
    e = (*v)(p->__pyx_v_flt, a); if (e) return e;
  }
  if (p->__pyx_v_gc) {
    e = (*v)(p->__pyx_v_gc, a); if (e) return e;
  }
  if (p->__pyx_v_genexpr) {
    e = (*v)(p->__pyx_v_genexpr, a); if (e) return e;
  }
  if (p->__pyx_v_it) {
    e = (*v)(p->__pyx_v_it, a); if (e) return e;
  }
  if (p->__pyx_v_kwargs) {
    e = (*v)(p->__pyx_v_kwargs, a); if (e) return e;
  }
  if (p->__pyx_v_one_based) {
    e = (*v)(p->__pyx_v_one_based, a); if (e) return e;
  }
  if (p->__pyx_v_rec) {
    e = (*v)(p->__pyx_v_rec, a); if (e) return e;
  }
  if (p->__pyx_v_recs) {
    e = (*v)(p->__pyx_v_recs, a); if (e) return e;
  }
  if (p->__pyx_v_samfile) {
    e = (*v)(((PyObject*)p->__pyx_v_samfile), a); if (e) return e;
  }
  if (p->__pyx_v_start) {
    e = (*v)(p->__pyx_v_start, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_v_a);
  p->__pyx_v_a = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_b);
  p->__pyx_v_b = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_chrom);
  p->__pyx_v_chrom = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp);
  p->__pyx_v_dp = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_mean);
  p->__pyx_v_dp_mean = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_mean_bygc);
  p->__pyx_v_dp_mean_bygc = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_median);
  p->__pyx_v_dp_median = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_median_bygc);
  p->__pyx_v_dp_median_bygc = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_normed_mean);
  p->__pyx_v_dp_normed_mean = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_normed_mean_bygc);
  p->__pyx_v_dp_normed_mean_bygc = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_normed_median);
  p->__pyx_v_dp_normed_median = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_normed_median_bygc);
  p->__pyx_v_dp_normed_median_bygc = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_percentile);
  p->__pyx_v_dp_percentile = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_percentile_bygc);
  p->__pyx_v_dp_percentile_bygc = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_percentiles);
  p->__pyx_v_dp_percentiles = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_dp_percentiles_bygc);
  p->__pyx_v_dp_percentiles_bygc = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_end);
  p->__pyx_v_end = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_fafile);
  p->__pyx_v_fafile = ((struct __pyx_obj_5pysam_9csamtools_Fastafile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_flt);
  p->__pyx_v_flt = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_gc);
  p->__pyx_v_gc = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_genexpr);
  p->__pyx_v_genexpr = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_it);
  p->__pyx_v_it = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_kwargs);
  p->__pyx_v_kwargs = ((PyObject*)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_one_based);
  p->__pyx_v_one_based = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_rec);
  p->__pyx_v_rec = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_recs);
  p->__pyx_v_recs = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_samfile);
  p->__pyx_v_samfile = ((struct __pyx_obj_5pysam_9csamtools_Samfile *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_start);
  p->__pyx_v_start = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_17_stat_coverage_normed_gc = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_17_stat_coverage_normed_gc = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_17_stat_coverage_normed_gc = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_17_stat_coverage_normed_gc = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_17_stat_coverage_normed_gc"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  #if PY_MAJOR_VERSION < 3
  0, /*tp_compare*/
  #else
  0, /*reserved*/
  #endif
  0, /*tp_repr*/
  &__pyx_tp_as_number___pyx_scope_struct_17_stat_coverage_normed_gc, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_17_stat_coverage_normed_gc, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_17_stat_coverage_normed_gc, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_17_stat_coverage_normed_gc, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc, /*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_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyObject *__pyx_tp_new_10pysamstats___pyx_scope_struct_18_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *)o);
  p->__pyx_outer_scope = 0;
  p->__pyx_v_rec = 0;
  p->__pyx_t_0 = 0;
  return o;
}

static void __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_18_genexpr(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *)o;
  PyObject_GC_UnTrack(o);
  Py_CLEAR(p->__pyx_outer_scope);
  Py_CLEAR(p->__pyx_v_rec);
  Py_CLEAR(p->__pyx_t_0);
  PyObject_GC_Track(o);
  (*Py_TYPE(o)->tp_free)(o);
}

static int __pyx_tp_traverse_10pysamstats___pyx_scope_struct_18_genexpr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *)o;
  if (p->__pyx_outer_scope) {
    e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e;
  }
  if (p->__pyx_v_rec) {
    e = (*v)(p->__pyx_v_rec, a); if (e) return e;
  }
  if (p->__pyx_t_0) {
    e = (*v)(p->__pyx_t_0, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_10pysamstats___pyx_scope_struct_18_genexpr(PyObject *o) {
  struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *p = (struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr *)o;
  PyObject* tmp;
  tmp = ((PyObject*)p->__pyx_outer_scope);
  p->__pyx_outer_scope = ((struct __pyx_obj_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc *)Py_None); Py_INCREF(Py_None);
  Py_XDECREF(tmp);
  tmp = ((PyObject*)p->__pyx_v_rec);
  p->__pyx_v_rec = 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);
  return 0;
}

static PyMethodDef __pyx_methods_10pysamstats___pyx_scope_struct_18_genexpr[] = {
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_18_genexpr = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_divide*/
  #endif
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_coerce*/
  #endif
  0, /*nb_int*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_long*/
  #else
  0, /*reserved*/
  #endif
  0, /*nb_float*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_oct*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*nb_hex*/
  #endif
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  #if PY_MAJOR_VERSION < 3
  0, /*nb_inplace_divide*/
  #endif
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if PY_VERSION_HEX >= 0x02050000
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_18_genexpr = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_18_genexpr = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_18_genexpr = {
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getreadbuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getwritebuffer*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getsegcount*/
  #endif
  #if PY_MAJOR_VERSION < 3
  0, /*bf_getcharbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_getbuffer*/
  #endif
  #if PY_VERSION_HEX >= 0x02060000
  0, /*bf_releasebuffer*/
  #endif
};

static PyTypeObject __pyx_type_10pysamstats___pyx_scope_struct_18_genexpr = {
  PyVarObject_HEAD_INIT(0, 0)
  __Pyx_NAMESTR("pysamstats.__pyx_scope_struct_18_genexpr"), /*tp_name*/
  sizeof(struct __pyx_obj_10pysamstats___pyx_scope_struct_18_genexpr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_10pysamstats___pyx_scope_struct_18_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*/
  &__pyx_tp_as_number___pyx_scope_struct_18_genexpr, /*tp_as_number*/
  &__pyx_tp_as_sequence___pyx_scope_struct_18_genexpr, /*tp_as_sequence*/
  &__pyx_tp_as_mapping___pyx_scope_struct_18_genexpr, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer___pyx_scope_struct_18_genexpr, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_10pysamstats___pyx_scope_struct_18_genexpr, /*tp_traverse*/
  __pyx_tp_clear_10pysamstats___pyx_scope_struct_18_genexpr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_10pysamstats___pyx_scope_struct_18_genexpr, /*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_10pysamstats___pyx_scope_struct_18_genexpr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
  0, /*tp_del*/
  #if PY_VERSION_HEX >= 0x02060000
  0, /*tp_version_tag*/
  #endif
};

static PyMethodDef __pyx_methods[] = {
  {__Pyx_NAMESTR("construct_rec_coverage"), (PyCFunction)__pyx_pw_10pysamstats_1construct_rec_coverage, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_coverage_strand"), (PyCFunction)__pyx_pw_10pysamstats_8construct_rec_coverage_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_coverage_ext"), (PyCFunction)__pyx_pw_10pysamstats_15construct_rec_coverage_ext, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_coverage_ext_strand"), (PyCFunction)__pyx_pw_10pysamstats_22construct_rec_coverage_ext_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_variation"), (PyCFunction)__pyx_pw_10pysamstats_29construct_rec_variation, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_variation_strand"), (PyCFunction)__pyx_pw_10pysamstats_36construct_rec_variation_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_tlen"), (PyCFunction)__pyx_pw_10pysamstats_43construct_rec_tlen, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_tlen_strand"), (PyCFunction)__pyx_pw_10pysamstats_50construct_rec_tlen_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_mapq"), (PyCFunction)__pyx_pw_10pysamstats_57construct_rec_mapq, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_mapq_strand"), (PyCFunction)__pyx_pw_10pysamstats_64construct_rec_mapq_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_baseq"), (PyCFunction)__pyx_pw_10pysamstats_71construct_rec_baseq, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_baseq_strand"), (PyCFunction)__pyx_pw_10pysamstats_78construct_rec_baseq_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_baseq_ext"), (PyCFunction)__pyx_pw_10pysamstats_85construct_rec_baseq_ext, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {__Pyx_NAMESTR("construct_rec_baseq_ext_strand"), (PyCFunction)__pyx_pw_10pysamstats_92construct_rec_baseq_ext_strand, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)},
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    __Pyx_NAMESTR("pysamstats"),
    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_n_s_10, __pyx_k_10, sizeof(__pyx_k_10), 0, 0, 1, 1},
  {&__pyx_n_s_102, __pyx_k_102, sizeof(__pyx_k_102), 0, 0, 1, 1},
  {&__pyx_n_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 1},
  {&__pyx_n_s_111, __pyx_k_111, sizeof(__pyx_k_111), 0, 0, 1, 1},
  {&__pyx_n_s_12, __pyx_k_12, sizeof(__pyx_k_12), 0, 0, 1, 1},
  {&__pyx_n_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 1},
  {&__pyx_n_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 1},
  {&__pyx_n_s_144, __pyx_k_144, sizeof(__pyx_k_144), 0, 0, 1, 1},
  {&__pyx_n_s_149, __pyx_k_149, sizeof(__pyx_k_149), 0, 0, 1, 1},
  {&__pyx_n_s_15, __pyx_k_15, sizeof(__pyx_k_15), 0, 0, 1, 1},
  {&__pyx_n_s_154, __pyx_k_154, sizeof(__pyx_k_154), 0, 0, 1, 1},
  {&__pyx_n_s_159, __pyx_k_159, sizeof(__pyx_k_159), 0, 0, 1, 1},
  {&__pyx_n_s_16, __pyx_k_16, sizeof(__pyx_k_16), 0, 0, 1, 1},
  {&__pyx_n_s_17, __pyx_k_17, sizeof(__pyx_k_17), 0, 0, 1, 1},
  {&__pyx_n_s_20, __pyx_k_20, sizeof(__pyx_k_20), 0, 0, 1, 1},
  {&__pyx_n_s_25, __pyx_k_25, sizeof(__pyx_k_25), 0, 0, 1, 1},
  {&__pyx_n_s_38, __pyx_k_38, sizeof(__pyx_k_38), 0, 0, 1, 1},
  {&__pyx_n_s_39, __pyx_k_39, sizeof(__pyx_k_39), 0, 0, 1, 1},
  {&__pyx_n_s_40, __pyx_k_40, sizeof(__pyx_k_40), 0, 0, 1, 1},
  {&__pyx_n_s_43, __pyx_k_43, sizeof(__pyx_k_43), 0, 0, 1, 1},
  {&__pyx_n_s_44, __pyx_k_44, sizeof(__pyx_k_44), 0, 0, 1, 1},
  {&__pyx_n_s_45, __pyx_k_45, sizeof(__pyx_k_45), 0, 0, 1, 1},
  {&__pyx_n_s_46, __pyx_k_46, sizeof(__pyx_k_46), 0, 0, 1, 1},
  {&__pyx_n_s_47, __pyx_k_47, sizeof(__pyx_k_47), 0, 0, 1, 1},
  {&__pyx_n_s_48, __pyx_k_48, sizeof(__pyx_k_48), 0, 0, 1, 1},
  {&__pyx_n_s_49, __pyx_k_49, sizeof(__pyx_k_49), 0, 0, 1, 1},
  {&__pyx_n_s_5, __pyx_k_5, sizeof(__pyx_k_5), 0, 0, 1, 1},
  {&__pyx_n_s_50, __pyx_k_50, sizeof(__pyx_k_50), 0, 0, 1, 1},
  {&__pyx_n_s_53, __pyx_k_53, sizeof(__pyx_k_53), 0, 0, 1, 1},
  {&__pyx_n_s_56, __pyx_k_56, sizeof(__pyx_k_56), 0, 0, 1, 1},
  {&__pyx_n_s_6, __pyx_k_6, sizeof(__pyx_k_6), 0, 0, 1, 1},
  {&__pyx_n_s_64, __pyx_k_64, sizeof(__pyx_k_64), 0, 0, 1, 1},
  {&__pyx_kp_s_68, __pyx_k_68, sizeof(__pyx_k_68), 0, 0, 1, 0},
  {&__pyx_kp_s_69, __pyx_k_69, sizeof(__pyx_k_69), 0, 0, 1, 0},
  {&__pyx_n_s_7, __pyx_k_7, sizeof(__pyx_k_7), 0, 0, 1, 1},
  {&__pyx_kp_u_70, __pyx_k_70, sizeof(__pyx_k_70), 0, 1, 0, 0},
  {&__pyx_kp_u_72, __pyx_k_72, sizeof(__pyx_k_72), 0, 1, 0, 0},
  {&__pyx_kp_u_74, __pyx_k_74, sizeof(__pyx_k_74), 0, 1, 0, 0},
  {&__pyx_kp_u_76, __pyx_k_76, sizeof(__pyx_k_76), 0, 1, 0, 0},
  {&__pyx_kp_u_77, __pyx_k_77, sizeof(__pyx_k_77), 0, 1, 0, 0},
  {&__pyx_kp_u_80, __pyx_k_80, sizeof(__pyx_k_80), 0, 1, 0, 0},
  {&__pyx_kp_s_82, __pyx_k_82, sizeof(__pyx_k_82), 0, 0, 1, 0},
  {&__pyx_kp_s_86, __pyx_k_86, sizeof(__pyx_k_86), 0, 0, 1, 0},
  {&__pyx_n_s_93, __pyx_k_93, sizeof(__pyx_k_93), 0, 0, 1, 1},
  {&__pyx_n_s__A, __pyx_k__A, sizeof(__pyx_k__A), 0, 0, 1, 1},
  {&__pyx_n_s__A_fwd, __pyx_k__A_fwd, sizeof(__pyx_k__A_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__A_pp, __pyx_k__A_pp, sizeof(__pyx_k__A_pp), 0, 0, 1, 1},
  {&__pyx_n_s__A_pp_fwd, __pyx_k__A_pp_fwd, sizeof(__pyx_k__A_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__A_pp_rev, __pyx_k__A_pp_rev, sizeof(__pyx_k__A_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__A_rev, __pyx_k__A_rev, sizeof(__pyx_k__A_rev), 0, 0, 1, 1},
  {&__pyx_n_s__C, __pyx_k__C, sizeof(__pyx_k__C), 0, 0, 1, 1},
  {&__pyx_n_s__C_fwd, __pyx_k__C_fwd, sizeof(__pyx_k__C_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__C_pp, __pyx_k__C_pp, sizeof(__pyx_k__C_pp), 0, 0, 1, 1},
  {&__pyx_n_s__C_pp_fwd, __pyx_k__C_pp_fwd, sizeof(__pyx_k__C_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__C_pp_rev, __pyx_k__C_pp_rev, sizeof(__pyx_k__C_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__C_rev, __pyx_k__C_rev, sizeof(__pyx_k__C_rev), 0, 0, 1, 1},
  {&__pyx_n_s__Counter, __pyx_k__Counter, sizeof(__pyx_k__Counter), 0, 0, 1, 1},
  {&__pyx_n_s__DictWriter, __pyx_k__DictWriter, sizeof(__pyx_k__DictWriter), 0, 0, 1, 1},
  {&__pyx_n_s__G, __pyx_k__G, sizeof(__pyx_k__G), 0, 0, 1, 1},
  {&__pyx_n_s__G_fwd, __pyx_k__G_fwd, sizeof(__pyx_k__G_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__G_pp, __pyx_k__G_pp, sizeof(__pyx_k__G_pp), 0, 0, 1, 1},
  {&__pyx_n_s__G_pp_fwd, __pyx_k__G_pp_fwd, sizeof(__pyx_k__G_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__G_pp_rev, __pyx_k__G_pp_rev, sizeof(__pyx_k__G_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__G_rev, __pyx_k__G_rev, sizeof(__pyx_k__G_rev), 0, 0, 1, 1},
  {&__pyx_n_s__N, __pyx_k__N, sizeof(__pyx_k__N), 0, 0, 1, 1},
  {&__pyx_n_s__NA, __pyx_k__NA, sizeof(__pyx_k__NA), 0, 0, 1, 1},
  {&__pyx_n_s__N_fwd, __pyx_k__N_fwd, sizeof(__pyx_k__N_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__N_pp, __pyx_k__N_pp, sizeof(__pyx_k__N_pp), 0, 0, 1, 1},
  {&__pyx_n_s__N_pp_fwd, __pyx_k__N_pp_fwd, sizeof(__pyx_k__N_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__N_pp_rev, __pyx_k__N_pp_rev, sizeof(__pyx_k__N_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__N_rev, __pyx_k__N_rev, sizeof(__pyx_k__N_rev), 0, 0, 1, 1},
  {&__pyx_n_s__RuntimeError, __pyx_k__RuntimeError, sizeof(__pyx_k__RuntimeError), 0, 0, 1, 1},
  {&__pyx_n_s__T, __pyx_k__T, sizeof(__pyx_k__T), 0, 0, 1, 1},
  {&__pyx_n_s__T_fwd, __pyx_k__T_fwd, sizeof(__pyx_k__T_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__T_pp, __pyx_k__T_pp, sizeof(__pyx_k__T_pp), 0, 0, 1, 1},
  {&__pyx_n_s__T_pp_fwd, __pyx_k__T_pp_fwd, sizeof(__pyx_k__T_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__T_pp_rev, __pyx_k__T_pp_rev, sizeof(__pyx_k__T_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__T_rev, __pyx_k__T_rev, sizeof(__pyx_k__T_rev), 0, 0, 1, 1},
  {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1},
  {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1},
  {&__pyx_n_s____test__, __pyx_k____test__, sizeof(__pyx_k____test__), 0, 0, 1, 1},
  {&__pyx_n_s____version__, __pyx_k____version__, sizeof(__pyx_k____version__), 0, 0, 1, 1},
  {&__pyx_n_s__a, __pyx_k__a, sizeof(__pyx_k__a), 0, 0, 1, 1},
  {&__pyx_n_s__after, __pyx_k__after, sizeof(__pyx_k__after), 0, 0, 1, 1},
  {&__pyx_n_s__after_all, __pyx_k__after_all, sizeof(__pyx_k__after_all), 0, 0, 1, 1},
  {&__pyx_n_s__args, __pyx_k__args, sizeof(__pyx_k__args), 0, 0, 1, 1},
  {&__pyx_n_s__b, __pyx_k__b, sizeof(__pyx_k__b), 0, 0, 1, 1},
  {&__pyx_n_s__batch_elapsed, __pyx_k__batch_elapsed, sizeof(__pyx_k__batch_elapsed), 0, 0, 1, 1},
  {&__pyx_n_s__before, __pyx_k__before, sizeof(__pyx_k__before), 0, 0, 1, 1},
  {&__pyx_n_s__before_all, __pyx_k__before_all, sizeof(__pyx_k__before_all), 0, 0, 1, 1},
  {&__pyx_n_s__bisect, __pyx_k__bisect, sizeof(__pyx_k__bisect), 0, 0, 1, 1},
  {&__pyx_n_s__bisect_left, __pyx_k__bisect_left, sizeof(__pyx_k__bisect_left), 0, 0, 1, 1},
  {&__pyx_n_s__chrom, __pyx_k__chrom, sizeof(__pyx_k__chrom), 0, 0, 1, 1},
  {&__pyx_n_s__col, __pyx_k__col, sizeof(__pyx_k__col), 0, 0, 1, 1},
  {&__pyx_n_s__collections, __pyx_k__collections, sizeof(__pyx_k__collections), 0, 0, 1, 1},
  {&__pyx_n_s__count_nonzero, __pyx_k__count_nonzero, sizeof(__pyx_k__count_nonzero), 0, 0, 1, 1},
  {&__pyx_n_s__counter, __pyx_k__counter, sizeof(__pyx_k__counter), 0, 0, 1, 1},
  {&__pyx_n_s__csv, __pyx_k__csv, sizeof(__pyx_k__csv), 0, 0, 1, 1},
  {&__pyx_n_s__deletions, __pyx_k__deletions, sizeof(__pyx_k__deletions), 0, 0, 1, 1},
  {&__pyx_n_s__deletions_fwd, __pyx_k__deletions_fwd, sizeof(__pyx_k__deletions_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__deletions_pp, __pyx_k__deletions_pp, sizeof(__pyx_k__deletions_pp), 0, 0, 1, 1},
  {&__pyx_n_s__deletions_pp_fwd, __pyx_k__deletions_pp_fwd, sizeof(__pyx_k__deletions_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__deletions_pp_rev, __pyx_k__deletions_pp_rev, sizeof(__pyx_k__deletions_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__deletions_rev, __pyx_k__deletions_rev, sizeof(__pyx_k__deletions_rev), 0, 0, 1, 1},
  {&__pyx_n_s__dialect, __pyx_k__dialect, sizeof(__pyx_k__dialect), 0, 0, 1, 1},
  {&__pyx_n_s__dp, __pyx_k__dp, sizeof(__pyx_k__dp), 0, 0, 1, 1},
  {&__pyx_n_s__dp_mean, __pyx_k__dp_mean, sizeof(__pyx_k__dp_mean), 0, 0, 1, 1},
  {&__pyx_n_s__dp_mean_bygc, __pyx_k__dp_mean_bygc, sizeof(__pyx_k__dp_mean_bygc), 0, 0, 1, 1},
  {&__pyx_n_s__dp_median, __pyx_k__dp_median, sizeof(__pyx_k__dp_median), 0, 0, 1, 1},
  {&__pyx_n_s__dp_median_bygc, __pyx_k__dp_median_bygc, sizeof(__pyx_k__dp_median_bygc), 0, 0, 1, 1},
  {&__pyx_n_s__dp_normed_mean, __pyx_k__dp_normed_mean, sizeof(__pyx_k__dp_normed_mean), 0, 0, 1, 1},
  {&__pyx_n_s__dp_normed_mean_bygc, __pyx_k__dp_normed_mean_bygc, sizeof(__pyx_k__dp_normed_mean_bygc), 0, 0, 1, 1},
  {&__pyx_n_s__dp_normed_mean_gc, __pyx_k__dp_normed_mean_gc, sizeof(__pyx_k__dp_normed_mean_gc), 0, 0, 1, 1},
  {&__pyx_n_s__dp_normed_median, __pyx_k__dp_normed_median, sizeof(__pyx_k__dp_normed_median), 0, 0, 1, 1},
  {&__pyx_n_s__dp_normed_median_gc, __pyx_k__dp_normed_median_gc, sizeof(__pyx_k__dp_normed_median_gc), 0, 0, 1, 1},
  {&__pyx_n_s__dp_percentile, __pyx_k__dp_percentile, sizeof(__pyx_k__dp_percentile), 0, 0, 1, 1},
  {&__pyx_n_s__dp_percentile_bygc, __pyx_k__dp_percentile_bygc, sizeof(__pyx_k__dp_percentile_bygc), 0, 0, 1, 1},
  {&__pyx_n_s__dp_percentile_gc, __pyx_k__dp_percentile_gc, sizeof(__pyx_k__dp_percentile_gc), 0, 0, 1, 1},
  {&__pyx_n_s__dp_percentiles, __pyx_k__dp_percentiles, sizeof(__pyx_k__dp_percentiles), 0, 0, 1, 1},
  {&__pyx_n_s__dp_percentiles_bygc, __pyx_k__dp_percentiles_bygc, sizeof(__pyx_k__dp_percentiles_bygc), 0, 0, 1, 1},
  {&__pyx_n_s__dtype, __pyx_k__dtype, sizeof(__pyx_k__dtype), 0, 0, 1, 1},
  {&__pyx_n_s__elapsed, __pyx_k__elapsed, sizeof(__pyx_k__elapsed), 0, 0, 1, 1},
  {&__pyx_n_s__elapsed_all, __pyx_k__elapsed_all, sizeof(__pyx_k__elapsed_all), 0, 0, 1, 1},
  {&__pyx_n_s__end, __pyx_k__end, sizeof(__pyx_k__end), 0, 0, 1, 1},
  {&__pyx_n_s__excel_tab, __pyx_k__excel_tab, sizeof(__pyx_k__excel_tab), 0, 0, 1, 1},
  {&__pyx_n_s__fafile, __pyx_k__fafile, sizeof(__pyx_k__fafile), 0, 0, 1, 1},
  {&__pyx_n_s__fetch, __pyx_k__fetch, sizeof(__pyx_k__fetch), 0, 0, 1, 1},
  {&__pyx_n_s__fieldnames, __pyx_k__fieldnames, sizeof(__pyx_k__fieldnames), 0, 0, 1, 1},
  {&__pyx_n_s__flt, __pyx_k__flt, sizeof(__pyx_k__flt), 0, 0, 1, 1},
  {&__pyx_n_s__fromiter, __pyx_k__fromiter, sizeof(__pyx_k__fromiter), 0, 0, 1, 1},
  {&__pyx_n_s__gc, __pyx_k__gc, sizeof(__pyx_k__gc), 0, 0, 1, 1},
  {&__pyx_n_s__gc_count, __pyx_k__gc_count, sizeof(__pyx_k__gc_count), 0, 0, 1, 1},
  {&__pyx_n_s__gc_percent, __pyx_k__gc_percent, sizeof(__pyx_k__gc_percent), 0, 0, 1, 1},
  {&__pyx_n_s__gc_window_length, __pyx_k__gc_window_length, sizeof(__pyx_k__gc_window_length), 0, 0, 1, 1},
  {&__pyx_n_s__gc_window_offset, __pyx_k__gc_window_offset, sizeof(__pyx_k__gc_window_offset), 0, 0, 1, 1},
  {&__pyx_n_s__genexpr, __pyx_k__genexpr, sizeof(__pyx_k__genexpr), 0, 0, 1, 1},
  {&__pyx_n_s__getrname, __pyx_k__getrname, sizeof(__pyx_k__getrname), 0, 0, 1, 1},
  {&__pyx_n_s__i, __pyx_k__i, sizeof(__pyx_k__i), 0, 0, 1, 1},
  {&__pyx_n_s__insertions, __pyx_k__insertions, sizeof(__pyx_k__insertions), 0, 0, 1, 1},
  {&__pyx_n_s__insertions_fwd, __pyx_k__insertions_fwd, sizeof(__pyx_k__insertions_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__insertions_pp, __pyx_k__insertions_pp, sizeof(__pyx_k__insertions_pp), 0, 0, 1, 1},
  {&__pyx_n_s__insertions_pp_fwd, __pyx_k__insertions_pp_fwd, sizeof(__pyx_k__insertions_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__insertions_pp_rev, __pyx_k__insertions_pp_rev, sizeof(__pyx_k__insertions_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__insertions_rev, __pyx_k__insertions_rev, sizeof(__pyx_k__insertions_rev), 0, 0, 1, 1},
  {&__pyx_n_s__it, __pyx_k__it, sizeof(__pyx_k__it), 0, 0, 1, 1},
  {&__pyx_n_s__kwargs, __pyx_k__kwargs, sizeof(__pyx_k__kwargs), 0, 0, 1, 1},
  {&__pyx_n_s__matches, __pyx_k__matches, sizeof(__pyx_k__matches), 0, 0, 1, 1},
  {&__pyx_n_s__matches_fwd, __pyx_k__matches_fwd, sizeof(__pyx_k__matches_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__matches_pp, __pyx_k__matches_pp, sizeof(__pyx_k__matches_pp), 0, 0, 1, 1},
  {&__pyx_n_s__matches_pp_fwd, __pyx_k__matches_pp_fwd, sizeof(__pyx_k__matches_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__matches_pp_rev, __pyx_k__matches_pp_rev, sizeof(__pyx_k__matches_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__matches_rev, __pyx_k__matches_rev, sizeof(__pyx_k__matches_rev), 0, 0, 1, 1},
  {&__pyx_n_s__max_mapq, __pyx_k__max_mapq, sizeof(__pyx_k__max_mapq), 0, 0, 1, 1},
  {&__pyx_n_s__max_mapq_fwd, __pyx_k__max_mapq_fwd, sizeof(__pyx_k__max_mapq_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__max_mapq_pp, __pyx_k__max_mapq_pp, sizeof(__pyx_k__max_mapq_pp), 0, 0, 1, 1},
  {&__pyx_n_s__max_mapq_pp_fwd, __pyx_k__max_mapq_pp_fwd, sizeof(__pyx_k__max_mapq_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__max_mapq_pp_rev, __pyx_k__max_mapq_pp_rev, sizeof(__pyx_k__max_mapq_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__max_mapq_rev, __pyx_k__max_mapq_rev, sizeof(__pyx_k__max_mapq_rev), 0, 0, 1, 1},
  {&__pyx_n_s__mean, __pyx_k__mean, sizeof(__pyx_k__mean), 0, 0, 1, 1},
  {&__pyx_n_s__mean_tlen, __pyx_k__mean_tlen, sizeof(__pyx_k__mean_tlen), 0, 0, 1, 1},
  {&__pyx_n_s__mean_tlen_fwd, __pyx_k__mean_tlen_fwd, sizeof(__pyx_k__mean_tlen_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__mean_tlen_pp, __pyx_k__mean_tlen_pp, sizeof(__pyx_k__mean_tlen_pp), 0, 0, 1, 1},
  {&__pyx_n_s__mean_tlen_pp_fwd, __pyx_k__mean_tlen_pp_fwd, sizeof(__pyx_k__mean_tlen_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__mean_tlen_pp_rev, __pyx_k__mean_tlen_pp_rev, sizeof(__pyx_k__mean_tlen_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__mean_tlen_rev, __pyx_k__mean_tlen_rev, sizeof(__pyx_k__mean_tlen_rev), 0, 0, 1, 1},
  {&__pyx_n_s__median, __pyx_k__median, sizeof(__pyx_k__median), 0, 0, 1, 1},
  {&__pyx_n_s__mismatches, __pyx_k__mismatches, sizeof(__pyx_k__mismatches), 0, 0, 1, 1},
  {&__pyx_n_s__mismatches_fwd, __pyx_k__mismatches_fwd, sizeof(__pyx_k__mismatches_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__mismatches_pp, __pyx_k__mismatches_pp, sizeof(__pyx_k__mismatches_pp), 0, 0, 1, 1},
  {&__pyx_n_s__mismatches_pp_fwd, __pyx_k__mismatches_pp_fwd, sizeof(__pyx_k__mismatches_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__mismatches_pp_rev, __pyx_k__mismatches_pp_rev, sizeof(__pyx_k__mismatches_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__mismatches_rev, __pyx_k__mismatches_rev, sizeof(__pyx_k__mismatches_rev), 0, 0, 1, 1},
  {&__pyx_n_s__modulus, __pyx_k__modulus, sizeof(__pyx_k__modulus), 0, 0, 1, 1},
  {&__pyx_n_s__n, __pyx_k__n, sizeof(__pyx_k__n), 0, 0, 1, 1},
  {&__pyx_n_s__normalise_coords, __pyx_k__normalise_coords, sizeof(__pyx_k__normalise_coords), 0, 0, 1, 1},
  {&__pyx_n_s__np, __pyx_k__np, sizeof(__pyx_k__np), 0, 0, 1, 1},
  {&__pyx_n_s__numpy, __pyx_k__numpy, sizeof(__pyx_k__numpy), 0, 0, 1, 1},
  {&__pyx_n_s__one_based, __pyx_k__one_based, sizeof(__pyx_k__one_based), 0, 0, 1, 1},
  {&__pyx_n_s__outfile, __pyx_k__outfile, sizeof(__pyx_k__outfile), 0, 0, 1, 1},
  {&__pyx_n_s__percentile, __pyx_k__percentile, sizeof(__pyx_k__percentile), 0, 0, 1, 1},
  {&__pyx_n_s__pileup, __pyx_k__pileup, sizeof(__pyx_k__pileup), 0, 0, 1, 1},
  {&__pyx_n_s__pos, __pyx_k__pos, sizeof(__pyx_k__pos), 0, 0, 1, 1},
  {&__pyx_n_s__progress, __pyx_k__progress, sizeof(__pyx_k__progress), 0, 0, 1, 1},
  {&__pyx_n_s__pysamstats, __pyx_k__pysamstats, sizeof(__pyx_k__pysamstats), 0, 0, 1, 1},
  {&__pyx_n_s__q, __pyx_k__q, sizeof(__pyx_k__q), 0, 0, 1, 1},
  {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1},
  {&__pyx_n_s__reads_all, __pyx_k__reads_all, sizeof(__pyx_k__reads_all), 0, 0, 1, 1},
  {&__pyx_n_s__reads_duplicate, __pyx_k__reads_duplicate, sizeof(__pyx_k__reads_duplicate), 0, 0, 1, 1},
  {&__pyx_n_s__reads_duplicate_fwd, __pyx_k__reads_duplicate_fwd, sizeof(__pyx_k__reads_duplicate_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__reads_duplicate_rev, __pyx_k__reads_duplicate_rev, sizeof(__pyx_k__reads_duplicate_rev), 0, 0, 1, 1},
  {&__pyx_n_s__reads_faceaway, __pyx_k__reads_faceaway, sizeof(__pyx_k__reads_faceaway), 0, 0, 1, 1},
  {&__pyx_n_s__reads_faceaway_fwd, __pyx_k__reads_faceaway_fwd, sizeof(__pyx_k__reads_faceaway_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__reads_faceaway_rev, __pyx_k__reads_faceaway_rev, sizeof(__pyx_k__reads_faceaway_rev), 0, 0, 1, 1},
  {&__pyx_n_s__reads_fwd, __pyx_k__reads_fwd, sizeof(__pyx_k__reads_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__reads_mapq0, __pyx_k__reads_mapq0, sizeof(__pyx_k__reads_mapq0), 0, 0, 1, 1},
  {&__pyx_n_s__reads_mapq0_fwd, __pyx_k__reads_mapq0_fwd, sizeof(__pyx_k__reads_mapq0_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__reads_mapq0_pp, __pyx_k__reads_mapq0_pp, sizeof(__pyx_k__reads_mapq0_pp), 0, 0, 1, 1},
  {&__pyx_n_s__reads_mapq0_pp_fwd, __pyx_k__reads_mapq0_pp_fwd, sizeof(__pyx_k__reads_mapq0_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__reads_mapq0_pp_rev, __pyx_k__reads_mapq0_pp_rev, sizeof(__pyx_k__reads_mapq0_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__reads_mapq0_rev, __pyx_k__reads_mapq0_rev, sizeof(__pyx_k__reads_mapq0_rev), 0, 0, 1, 1},
  {&__pyx_n_s__reads_mate_unmapped, __pyx_k__reads_mate_unmapped, sizeof(__pyx_k__reads_mate_unmapped), 0, 0, 1, 1},
  {&__pyx_n_s__reads_pp, __pyx_k__reads_pp, sizeof(__pyx_k__reads_pp), 0, 0, 1, 1},
  {&__pyx_n_s__reads_pp_fwd, __pyx_k__reads_pp_fwd, sizeof(__pyx_k__reads_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__reads_pp_rev, __pyx_k__reads_pp_rev, sizeof(__pyx_k__reads_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__reads_rev, __pyx_k__reads_rev, sizeof(__pyx_k__reads_rev), 0, 0, 1, 1},
  {&__pyx_n_s__reads_softclipped, __pyx_k__reads_softclipped, sizeof(__pyx_k__reads_softclipped), 0, 0, 1, 1},
  {&__pyx_n_s__rec, __pyx_k__rec, sizeof(__pyx_k__rec), 0, 0, 1, 1},
  {&__pyx_n_s__recarray, __pyx_k__recarray, sizeof(__pyx_k__recarray), 0, 0, 1, 1},
  {&__pyx_n_s__recs, __pyx_k__recs, sizeof(__pyx_k__recs), 0, 0, 1, 1},
  {&__pyx_n_s__ref, __pyx_k__ref, sizeof(__pyx_k__ref), 0, 0, 1, 1},
  {&__pyx_n_s__ref_window, __pyx_k__ref_window, sizeof(__pyx_k__ref_window), 0, 0, 1, 1},
  {&__pyx_n_s__ref_window_end, __pyx_k__ref_window_end, sizeof(__pyx_k__ref_window_end), 0, 0, 1, 1},
  {&__pyx_n_s__ref_window_start, __pyx_k__ref_window_start, sizeof(__pyx_k__ref_window_start), 0, 0, 1, 1},
  {&__pyx_n_s__reference, __pyx_k__reference, sizeof(__pyx_k__reference), 0, 0, 1, 1},
  {&__pyx_n_s__rms_baseq, __pyx_k__rms_baseq, sizeof(__pyx_k__rms_baseq), 0, 0, 1, 1},
  {&__pyx_n_s__rms_baseq_fwd, __pyx_k__rms_baseq_fwd, sizeof(__pyx_k__rms_baseq_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__rms_baseq_matches, __pyx_k__rms_baseq_matches, sizeof(__pyx_k__rms_baseq_matches), 0, 0, 1, 1},
  {&__pyx_n_s__rms_baseq_pp, __pyx_k__rms_baseq_pp, sizeof(__pyx_k__rms_baseq_pp), 0, 0, 1, 1},
  {&__pyx_n_s__rms_baseq_pp_fwd, __pyx_k__rms_baseq_pp_fwd, sizeof(__pyx_k__rms_baseq_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__rms_baseq_pp_rev, __pyx_k__rms_baseq_pp_rev, sizeof(__pyx_k__rms_baseq_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__rms_baseq_rev, __pyx_k__rms_baseq_rev, sizeof(__pyx_k__rms_baseq_rev), 0, 0, 1, 1},
  {&__pyx_n_s__rms_mapq, __pyx_k__rms_mapq, sizeof(__pyx_k__rms_mapq), 0, 0, 1, 1},
  {&__pyx_n_s__rms_mapq_fwd, __pyx_k__rms_mapq_fwd, sizeof(__pyx_k__rms_mapq_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__rms_mapq_pp, __pyx_k__rms_mapq_pp, sizeof(__pyx_k__rms_mapq_pp), 0, 0, 1, 1},
  {&__pyx_n_s__rms_mapq_pp_fwd, __pyx_k__rms_mapq_pp_fwd, sizeof(__pyx_k__rms_mapq_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__rms_mapq_pp_rev, __pyx_k__rms_mapq_pp_rev, sizeof(__pyx_k__rms_mapq_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__rms_mapq_rev, __pyx_k__rms_mapq_rev, sizeof(__pyx_k__rms_mapq_rev), 0, 0, 1, 1},
  {&__pyx_n_s__rms_tlen, __pyx_k__rms_tlen, sizeof(__pyx_k__rms_tlen), 0, 0, 1, 1},
  {&__pyx_n_s__rms_tlen_fwd, __pyx_k__rms_tlen_fwd, sizeof(__pyx_k__rms_tlen_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__rms_tlen_pp, __pyx_k__rms_tlen_pp, sizeof(__pyx_k__rms_tlen_pp), 0, 0, 1, 1},
  {&__pyx_n_s__rms_tlen_pp_fwd, __pyx_k__rms_tlen_pp_fwd, sizeof(__pyx_k__rms_tlen_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__rms_tlen_pp_rev, __pyx_k__rms_tlen_pp_rev, sizeof(__pyx_k__rms_tlen_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__rms_tlen_rev, __pyx_k__rms_tlen_rev, sizeof(__pyx_k__rms_tlen_rev), 0, 0, 1, 1},
  {&__pyx_n_s__round, __pyx_k__round, sizeof(__pyx_k__round), 0, 0, 1, 1},
  {&__pyx_n_s__samfile, __pyx_k__samfile, sizeof(__pyx_k__samfile), 0, 0, 1, 1},
  {&__pyx_n_s__seq, __pyx_k__seq, sizeof(__pyx_k__seq), 0, 0, 1, 1},
  {&__pyx_n_s__start, __pyx_k__start, sizeof(__pyx_k__start), 0, 0, 1, 1},
  {&__pyx_n_s__stat_baseq, __pyx_k__stat_baseq, sizeof(__pyx_k__stat_baseq), 0, 0, 1, 1},
  {&__pyx_n_s__stat_baseq_ext, __pyx_k__stat_baseq_ext, sizeof(__pyx_k__stat_baseq_ext), 0, 0, 1, 1},
  {&__pyx_n_s__stat_baseq_strand, __pyx_k__stat_baseq_strand, sizeof(__pyx_k__stat_baseq_strand), 0, 0, 1, 1},
  {&__pyx_n_s__stat_coverage, __pyx_k__stat_coverage, sizeof(__pyx_k__stat_coverage), 0, 0, 1, 1},
  {&__pyx_n_s__stat_coverage_ext, __pyx_k__stat_coverage_ext, sizeof(__pyx_k__stat_coverage_ext), 0, 0, 1, 1},
  {&__pyx_n_s__stat_coverage_gc, __pyx_k__stat_coverage_gc, sizeof(__pyx_k__stat_coverage_gc), 0, 0, 1, 1},
  {&__pyx_n_s__stat_mapq, __pyx_k__stat_mapq, sizeof(__pyx_k__stat_mapq), 0, 0, 1, 1},
  {&__pyx_n_s__stat_mapq_strand, __pyx_k__stat_mapq_strand, sizeof(__pyx_k__stat_mapq_strand), 0, 0, 1, 1},
  {&__pyx_n_s__stat_tlen, __pyx_k__stat_tlen, sizeof(__pyx_k__stat_tlen), 0, 0, 1, 1},
  {&__pyx_n_s__stat_tlen_strand, __pyx_k__stat_tlen_strand, sizeof(__pyx_k__stat_tlen_strand), 0, 0, 1, 1},
  {&__pyx_n_s__stat_variation, __pyx_k__stat_variation, sizeof(__pyx_k__stat_variation), 0, 0, 1, 1},
  {&__pyx_n_s__statfun, __pyx_k__statfun, sizeof(__pyx_k__statfun), 0, 0, 1, 1},
  {&__pyx_n_s__std_tlen, __pyx_k__std_tlen, sizeof(__pyx_k__std_tlen), 0, 0, 1, 1},
  {&__pyx_n_s__std_tlen_fwd, __pyx_k__std_tlen_fwd, sizeof(__pyx_k__std_tlen_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__std_tlen_pp, __pyx_k__std_tlen_pp, sizeof(__pyx_k__std_tlen_pp), 0, 0, 1, 1},
  {&__pyx_n_s__std_tlen_pp_fwd, __pyx_k__std_tlen_pp_fwd, sizeof(__pyx_k__std_tlen_pp_fwd), 0, 0, 1, 1},
  {&__pyx_n_s__std_tlen_pp_rev, __pyx_k__std_tlen_pp_rev, sizeof(__pyx_k__std_tlen_pp_rev), 0, 0, 1, 1},
  {&__pyx_n_s__std_tlen_rev, __pyx_k__std_tlen_rev, sizeof(__pyx_k__std_tlen_rev), 0, 0, 1, 1},
  {&__pyx_n_s__stderr, __pyx_k__stderr, sizeof(__pyx_k__stderr), 0, 0, 1, 1},
  {&__pyx_n_s__sys, __pyx_k__sys, sizeof(__pyx_k__sys), 0, 0, 1, 1},
  {&__pyx_n_s__tid, __pyx_k__tid, sizeof(__pyx_k__tid), 0, 0, 1, 1},
  {&__pyx_n_s__time, __pyx_k__time, sizeof(__pyx_k__time), 0, 0, 1, 1},
  {&__pyx_n_s__u1, __pyx_k__u1, sizeof(__pyx_k__u1), 0, 0, 1, 1},
  {&__pyx_n_s__u4, __pyx_k__u4, sizeof(__pyx_k__u4), 0, 0, 1, 1},
  {&__pyx_n_s__upper, __pyx_k__upper, sizeof(__pyx_k__upper), 0, 0, 1, 1},
  {&__pyx_n_s__view, __pyx_k__view, sizeof(__pyx_k__view), 0, 0, 1, 1},
  {&__pyx_n_s__write_baseq, __pyx_k__write_baseq, sizeof(__pyx_k__write_baseq), 0, 0, 1, 1},
  {&__pyx_n_s__write_baseq_ext, __pyx_k__write_baseq_ext, sizeof(__pyx_k__write_baseq_ext), 0, 0, 1, 1},
  {&__pyx_n_s__write_baseq_strand, __pyx_k__write_baseq_strand, sizeof(__pyx_k__write_baseq_strand), 0, 0, 1, 1},
  {&__pyx_n_s__write_coverage, __pyx_k__write_coverage, sizeof(__pyx_k__write_coverage), 0, 0, 1, 1},
  {&__pyx_n_s__write_coverage_ext, __pyx_k__write_coverage_ext, sizeof(__pyx_k__write_coverage_ext), 0, 0, 1, 1},
  {&__pyx_n_s__write_coverage_gc, __pyx_k__write_coverage_gc, sizeof(__pyx_k__write_coverage_gc), 0, 0, 1, 1},
  {&__pyx_n_s__write_header, __pyx_k__write_header, sizeof(__pyx_k__write_header), 0, 0, 1, 1},
  {&__pyx_n_s__write_mapq, __pyx_k__write_mapq, sizeof(__pyx_k__write_mapq), 0, 0, 1, 1},
  {&__pyx_n_s__write_mapq_strand, __pyx_k__write_mapq_strand, sizeof(__pyx_k__write_mapq_strand), 0, 0, 1, 1},
  {&__pyx_n_s__write_stats, __pyx_k__write_stats, sizeof(__pyx_k__write_stats), 0, 0, 1, 1},
  {&__pyx_n_s__write_tlen, __pyx_k__write_tlen, sizeof(__pyx_k__write_tlen), 0, 0, 1, 1},
  {&__pyx_n_s__write_tlen_strand, __pyx_k__write_tlen_strand, sizeof(__pyx_k__write_tlen_strand), 0, 0, 1, 1},
  {&__pyx_n_s__write_variation, __pyx_k__write_variation, sizeof(__pyx_k__write_variation), 0, 0, 1, 1},
  {&__pyx_n_s__writeheader, __pyx_k__writeheader, sizeof(__pyx_k__writeheader), 0, 0, 1, 1},
  {&__pyx_n_s__writer, __pyx_k__writer, sizeof(__pyx_k__writer), 0, 0, 1, 1},
  {&__pyx_n_s__writerow, __pyx_k__writerow, sizeof(__pyx_k__writerow), 0, 0, 1, 1},
  {&__pyx_n_s__writerows, __pyx_k__writerows, sizeof(__pyx_k__writerows), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_round = __Pyx_GetName(__pyx_b, __pyx_n_s__round); if (!__pyx_builtin_round) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_RuntimeError = __Pyx_GetName(__pyx_b, __pyx_n_s__RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __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);

  /* "pysamstats.pyx":107
 * 
 * def write_coverage(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'reads_all', 'reads_pp')             # <<<<<<<<<<<<<<
 *     write_stats(stat_coverage, fieldnames, *args, **kwargs)
 * 
 */
  __pyx_k_tuple_2 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_2);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_2, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_2, 2, ((PyObject *)__pyx_n_s__reads_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_2, 3, ((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));

  /* "pysamstats.pyx":176
 * 
 * def write_coverage_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *                   'reads_all', 'reads_fwd', 'reads_rev',
 *                   'reads_pp', 'reads_pp_fwd', 'reads_pp_rev')
 */
  __pyx_k_tuple_4 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_4);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_4, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_4, 2, ((PyObject *)__pyx_n_s__reads_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_4, 3, ((PyObject *)__pyx_n_s__reads_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_4, 4, ((PyObject *)__pyx_n_s__reads_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_4, 5, ((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_4, 6, ((PyObject *)__pyx_n_s__reads_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_4, 7, ((PyObject *)__pyx_n_s__reads_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));

  /* "pysamstats.pyx":263
 * 
 * def write_coverage_ext(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *                   'reads_all',
 *                   'reads_pp',
 */
  __pyx_k_tuple_9 = PyTuple_New(10); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_9);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_9, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_9, 2, ((PyObject *)__pyx_n_s__reads_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_9, 3, ((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_mate_unmapped));
  PyTuple_SET_ITEM(__pyx_k_tuple_9, 4, ((PyObject *)__pyx_n_s__reads_mate_unmapped));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_mate_unmapped));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_6));
  PyTuple_SET_ITEM(__pyx_k_tuple_9, 5, ((PyObject *)__pyx_n_s_6));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_6));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_7));
  PyTuple_SET_ITEM(__pyx_k_tuple_9, 6, ((PyObject *)__pyx_n_s_7));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_7));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_faceaway));
  PyTuple_SET_ITEM(__pyx_k_tuple_9, 7, ((PyObject *)__pyx_n_s__reads_faceaway));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_faceaway));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_softclipped));
  PyTuple_SET_ITEM(__pyx_k_tuple_9, 8, ((PyObject *)__pyx_n_s__reads_softclipped));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_softclipped));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_duplicate));
  PyTuple_SET_ITEM(__pyx_k_tuple_9, 9, ((PyObject *)__pyx_n_s__reads_duplicate));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_duplicate));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_9));

  /* "pysamstats.pyx":421
 * 
 * def write_coverage_ext_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *                   'reads_all',
 *                   'reads_fwd',
 */
  __pyx_k_tuple_19 = PyTuple_New(26); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 421; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_19);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 2, ((PyObject *)__pyx_n_s__reads_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 3, ((PyObject *)__pyx_n_s__reads_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 4, ((PyObject *)__pyx_n_s__reads_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 5, ((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 6, ((PyObject *)__pyx_n_s__reads_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 7, ((PyObject *)__pyx_n_s__reads_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_mate_unmapped));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 8, ((PyObject *)__pyx_n_s__reads_mate_unmapped));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_mate_unmapped));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_10));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 9, ((PyObject *)__pyx_n_s_10));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_10));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_11));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 10, ((PyObject *)__pyx_n_s_11));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_11));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_6));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 11, ((PyObject *)__pyx_n_s_6));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_6));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_12));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 12, ((PyObject *)__pyx_n_s_12));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_12));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_13));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 13, ((PyObject *)__pyx_n_s_13));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_13));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_7));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 14, ((PyObject *)__pyx_n_s_7));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_7));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_14));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 15, ((PyObject *)__pyx_n_s_14));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_14));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_15));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 16, ((PyObject *)__pyx_n_s_15));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_15));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_faceaway));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 17, ((PyObject *)__pyx_n_s__reads_faceaway));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_faceaway));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_faceaway_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 18, ((PyObject *)__pyx_n_s__reads_faceaway_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_faceaway_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_faceaway_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 19, ((PyObject *)__pyx_n_s__reads_faceaway_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_faceaway_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_softclipped));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 20, ((PyObject *)__pyx_n_s__reads_softclipped));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_softclipped));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_16));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 21, ((PyObject *)__pyx_n_s_16));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_16));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_17));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 22, ((PyObject *)__pyx_n_s_17));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_17));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_duplicate));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 23, ((PyObject *)__pyx_n_s__reads_duplicate));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_duplicate));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_duplicate_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 24, ((PyObject *)__pyx_n_s__reads_duplicate_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_duplicate_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_duplicate_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_19, 25, ((PyObject *)__pyx_n_s__reads_duplicate_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_duplicate_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19));

  /* "pysamstats.pyx":574
 * 
 * def write_variation(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'ref',             # <<<<<<<<<<<<<<
 *                   'reads_all', 'reads_pp',
 *                   'matches', 'matches_pp',
 */
  __pyx_k_tuple_22 = PyTuple_New(23); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_22);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ref));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 2, ((PyObject *)__pyx_n_s__ref));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ref));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 3, ((PyObject *)__pyx_n_s__reads_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 4, ((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__matches));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 5, ((PyObject *)__pyx_n_s__matches));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__matches));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__matches_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 6, ((PyObject *)__pyx_n_s__matches_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__matches_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mismatches));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 7, ((PyObject *)__pyx_n_s__mismatches));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mismatches));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mismatches_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 8, ((PyObject *)__pyx_n_s__mismatches_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mismatches_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deletions));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 9, ((PyObject *)__pyx_n_s__deletions));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deletions));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deletions_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 10, ((PyObject *)__pyx_n_s__deletions_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deletions_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__insertions));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 11, ((PyObject *)__pyx_n_s__insertions));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__insertions));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__insertions_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 12, ((PyObject *)__pyx_n_s__insertions_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__insertions_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__A));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 13, ((PyObject *)__pyx_n_s__A));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__A));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__A_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 14, ((PyObject *)__pyx_n_s__A_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__A_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__C));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 15, ((PyObject *)__pyx_n_s__C));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__C));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__C_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 16, ((PyObject *)__pyx_n_s__C_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__C_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__T));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 17, ((PyObject *)__pyx_n_s__T));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__T));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__T_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 18, ((PyObject *)__pyx_n_s__T_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__T_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__G));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 19, ((PyObject *)__pyx_n_s__G));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__G));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__G_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 20, ((PyObject *)__pyx_n_s__G_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__G_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__N));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 21, ((PyObject *)__pyx_n_s__N));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__N));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__N_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_22, 22, ((PyObject *)__pyx_n_s__N_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__N_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22));

  /* "pysamstats.pyx":705
 * 
 * def write_variation_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'ref',             # <<<<<<<<<<<<<<
 *                 'reads_all', 'reads_fwd', 'reads_rev', 'reads_pp', 'reads_pp_fwd', 'reads_pp_rev',
 *                 'matches', 'matches_fwd', 'matches_rev', 'matches_pp', 'matches_pp_fwd', 'matches_pp_rev',
 */
  __pyx_k_tuple_24 = PyTuple_New(63); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_24);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ref));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 2, ((PyObject *)__pyx_n_s__ref));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ref));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 3, ((PyObject *)__pyx_n_s__reads_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 4, ((PyObject *)__pyx_n_s__reads_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 5, ((PyObject *)__pyx_n_s__reads_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 6, ((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 7, ((PyObject *)__pyx_n_s__reads_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 8, ((PyObject *)__pyx_n_s__reads_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__matches));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 9, ((PyObject *)__pyx_n_s__matches));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__matches));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__matches_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 10, ((PyObject *)__pyx_n_s__matches_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__matches_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__matches_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 11, ((PyObject *)__pyx_n_s__matches_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__matches_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__matches_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 12, ((PyObject *)__pyx_n_s__matches_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__matches_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__matches_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 13, ((PyObject *)__pyx_n_s__matches_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__matches_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__matches_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 14, ((PyObject *)__pyx_n_s__matches_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__matches_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mismatches));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 15, ((PyObject *)__pyx_n_s__mismatches));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mismatches));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mismatches_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 16, ((PyObject *)__pyx_n_s__mismatches_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mismatches_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mismatches_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 17, ((PyObject *)__pyx_n_s__mismatches_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mismatches_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mismatches_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 18, ((PyObject *)__pyx_n_s__mismatches_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mismatches_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mismatches_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 19, ((PyObject *)__pyx_n_s__mismatches_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mismatches_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mismatches_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 20, ((PyObject *)__pyx_n_s__mismatches_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mismatches_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deletions));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 21, ((PyObject *)__pyx_n_s__deletions));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deletions));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deletions_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 22, ((PyObject *)__pyx_n_s__deletions_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deletions_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deletions_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 23, ((PyObject *)__pyx_n_s__deletions_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deletions_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deletions_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 24, ((PyObject *)__pyx_n_s__deletions_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deletions_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deletions_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 25, ((PyObject *)__pyx_n_s__deletions_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deletions_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__deletions_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 26, ((PyObject *)__pyx_n_s__deletions_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__deletions_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__insertions));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 27, ((PyObject *)__pyx_n_s__insertions));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__insertions));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__insertions_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 28, ((PyObject *)__pyx_n_s__insertions_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__insertions_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__insertions_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 29, ((PyObject *)__pyx_n_s__insertions_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__insertions_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__insertions_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 30, ((PyObject *)__pyx_n_s__insertions_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__insertions_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__insertions_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 31, ((PyObject *)__pyx_n_s__insertions_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__insertions_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__insertions_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 32, ((PyObject *)__pyx_n_s__insertions_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__insertions_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__A));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 33, ((PyObject *)__pyx_n_s__A));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__A));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__A_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 34, ((PyObject *)__pyx_n_s__A_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__A_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__A_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 35, ((PyObject *)__pyx_n_s__A_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__A_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__A_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 36, ((PyObject *)__pyx_n_s__A_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__A_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__A_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 37, ((PyObject *)__pyx_n_s__A_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__A_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__A_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 38, ((PyObject *)__pyx_n_s__A_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__A_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__C));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 39, ((PyObject *)__pyx_n_s__C));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__C));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__C_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 40, ((PyObject *)__pyx_n_s__C_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__C_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__C_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 41, ((PyObject *)__pyx_n_s__C_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__C_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__C_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 42, ((PyObject *)__pyx_n_s__C_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__C_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__C_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 43, ((PyObject *)__pyx_n_s__C_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__C_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__C_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 44, ((PyObject *)__pyx_n_s__C_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__C_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__T));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 45, ((PyObject *)__pyx_n_s__T));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__T));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__T_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 46, ((PyObject *)__pyx_n_s__T_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__T_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__T_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 47, ((PyObject *)__pyx_n_s__T_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__T_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__T_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 48, ((PyObject *)__pyx_n_s__T_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__T_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__T_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 49, ((PyObject *)__pyx_n_s__T_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__T_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__T_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 50, ((PyObject *)__pyx_n_s__T_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__T_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__G));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 51, ((PyObject *)__pyx_n_s__G));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__G));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__G_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 52, ((PyObject *)__pyx_n_s__G_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__G_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__G_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 53, ((PyObject *)__pyx_n_s__G_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__G_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__G_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 54, ((PyObject *)__pyx_n_s__G_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__G_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__G_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 55, ((PyObject *)__pyx_n_s__G_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__G_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__G_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 56, ((PyObject *)__pyx_n_s__G_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__G_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__N));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 57, ((PyObject *)__pyx_n_s__N));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__N));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__N_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 58, ((PyObject *)__pyx_n_s__N_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__N_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__N_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 59, ((PyObject *)__pyx_n_s__N_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__N_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__N_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 60, ((PyObject *)__pyx_n_s__N_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__N_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__N_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 61, ((PyObject *)__pyx_n_s__N_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__N_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__N_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_24, 62, ((PyObject *)__pyx_n_s__N_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__N_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24));

  /* "pysamstats.pyx":846
 * 
 * def write_tlen(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *  #                 'reads_all', 'reads_paired', 'reads_pp',
 *                   'mean_tlen', 'mean_tlen_pp',
 */
  __pyx_k_tuple_27 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_27)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_27);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_27, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_27, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mean_tlen));
  PyTuple_SET_ITEM(__pyx_k_tuple_27, 2, ((PyObject *)__pyx_n_s__mean_tlen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mean_tlen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mean_tlen_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_27, 3, ((PyObject *)__pyx_n_s__mean_tlen_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mean_tlen_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_tlen));
  PyTuple_SET_ITEM(__pyx_k_tuple_27, 4, ((PyObject *)__pyx_n_s__rms_tlen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_tlen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_tlen_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_27, 5, ((PyObject *)__pyx_n_s__rms_tlen_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_tlen_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__std_tlen));
  PyTuple_SET_ITEM(__pyx_k_tuple_27, 6, ((PyObject *)__pyx_n_s__std_tlen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__std_tlen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__std_tlen_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_27, 7, ((PyObject *)__pyx_n_s__std_tlen_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__std_tlen_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_27));

  /* "pysamstats.pyx":1103
 * 
 * def write_tlen_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 * #                  'reads_paired', 'reads_paired_fwd', 'reads_paired_rev',
 */
  __pyx_k_tuple_29 = PyTuple_New(20); if (unlikely(!__pyx_k_tuple_29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1103; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_29);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mean_tlen));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 2, ((PyObject *)__pyx_n_s__mean_tlen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mean_tlen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mean_tlen_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 3, ((PyObject *)__pyx_n_s__mean_tlen_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mean_tlen_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mean_tlen_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 4, ((PyObject *)__pyx_n_s__mean_tlen_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mean_tlen_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mean_tlen_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 5, ((PyObject *)__pyx_n_s__mean_tlen_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mean_tlen_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mean_tlen_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 6, ((PyObject *)__pyx_n_s__mean_tlen_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mean_tlen_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__mean_tlen_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 7, ((PyObject *)__pyx_n_s__mean_tlen_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__mean_tlen_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_tlen));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 8, ((PyObject *)__pyx_n_s__rms_tlen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_tlen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_tlen_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 9, ((PyObject *)__pyx_n_s__rms_tlen_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_tlen_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_tlen_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 10, ((PyObject *)__pyx_n_s__rms_tlen_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_tlen_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_tlen_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 11, ((PyObject *)__pyx_n_s__rms_tlen_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_tlen_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_tlen_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 12, ((PyObject *)__pyx_n_s__rms_tlen_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_tlen_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_tlen_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 13, ((PyObject *)__pyx_n_s__rms_tlen_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_tlen_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__std_tlen));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 14, ((PyObject *)__pyx_n_s__std_tlen));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__std_tlen));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__std_tlen_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 15, ((PyObject *)__pyx_n_s__std_tlen_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__std_tlen_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__std_tlen_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 16, ((PyObject *)__pyx_n_s__std_tlen_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__std_tlen_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__std_tlen_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 17, ((PyObject *)__pyx_n_s__std_tlen_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__std_tlen_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__std_tlen_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 18, ((PyObject *)__pyx_n_s__std_tlen_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__std_tlen_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__std_tlen_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_29, 19, ((PyObject *)__pyx_n_s__std_tlen_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__std_tlen_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_29));

  /* "pysamstats.pyx":1198
 * 
 * def write_mapq(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *                   'reads_all', 'reads_pp',
 *                   'reads_mapq0', 'reads_mapq0_pp',
 */
  __pyx_k_tuple_31 = PyTuple_New(10); if (unlikely(!__pyx_k_tuple_31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1198; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_31);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 2, ((PyObject *)__pyx_n_s__reads_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 3, ((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_mapq0));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 4, ((PyObject *)__pyx_n_s__reads_mapq0));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_mapq0));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_mapq0_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 5, ((PyObject *)__pyx_n_s__reads_mapq0_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_mapq0_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_mapq));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 6, ((PyObject *)__pyx_n_s__rms_mapq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_mapq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_mapq_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 7, ((PyObject *)__pyx_n_s__rms_mapq_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_mapq_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__max_mapq));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 8, ((PyObject *)__pyx_n_s__max_mapq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_mapq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__max_mapq_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_31, 9, ((PyObject *)__pyx_n_s__max_mapq_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_mapq_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_31));

  /* "pysamstats.pyx":1377
 * 
 * def write_mapq_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 *                   'reads_all', 'reads_fwd', 'reads_rev',
 *                   'reads_pp', 'reads_pp_fwd', 'reads_pp_rev',
 */
  __pyx_k_tuple_33 = PyTuple_New(26); if (unlikely(!__pyx_k_tuple_33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1377; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_33);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 2, ((PyObject *)__pyx_n_s__reads_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 3, ((PyObject *)__pyx_n_s__reads_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 4, ((PyObject *)__pyx_n_s__reads_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 5, ((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 6, ((PyObject *)__pyx_n_s__reads_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 7, ((PyObject *)__pyx_n_s__reads_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_mapq0));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 8, ((PyObject *)__pyx_n_s__reads_mapq0));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_mapq0));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_mapq0_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 9, ((PyObject *)__pyx_n_s__reads_mapq0_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_mapq0_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_mapq0_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 10, ((PyObject *)__pyx_n_s__reads_mapq0_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_mapq0_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_mapq0_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 11, ((PyObject *)__pyx_n_s__reads_mapq0_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_mapq0_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_mapq0_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 12, ((PyObject *)__pyx_n_s__reads_mapq0_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_mapq0_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_mapq0_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 13, ((PyObject *)__pyx_n_s__reads_mapq0_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_mapq0_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_mapq));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 14, ((PyObject *)__pyx_n_s__rms_mapq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_mapq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_mapq_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 15, ((PyObject *)__pyx_n_s__rms_mapq_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_mapq_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_mapq_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 16, ((PyObject *)__pyx_n_s__rms_mapq_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_mapq_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_mapq_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 17, ((PyObject *)__pyx_n_s__rms_mapq_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_mapq_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_mapq_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 18, ((PyObject *)__pyx_n_s__rms_mapq_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_mapq_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_mapq_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 19, ((PyObject *)__pyx_n_s__rms_mapq_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_mapq_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__max_mapq));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 20, ((PyObject *)__pyx_n_s__max_mapq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_mapq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__max_mapq_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 21, ((PyObject *)__pyx_n_s__max_mapq_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_mapq_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__max_mapq_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 22, ((PyObject *)__pyx_n_s__max_mapq_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_mapq_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__max_mapq_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 23, ((PyObject *)__pyx_n_s__max_mapq_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_mapq_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__max_mapq_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 24, ((PyObject *)__pyx_n_s__max_mapq_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_mapq_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__max_mapq_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_33, 25, ((PyObject *)__pyx_n_s__max_mapq_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__max_mapq_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_33));

  /* "pysamstats.pyx":1457
 * 
 * def write_baseq(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 * #                  'reads_all',
 * #                  'reads_pp',
 */
  __pyx_k_tuple_35 = PyTuple_New(4); if (unlikely(!__pyx_k_tuple_35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_35);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 2, ((PyObject *)__pyx_n_s__rms_baseq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_35, 3, ((PyObject *)__pyx_n_s__rms_baseq_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_35));

  /* "pysamstats.pyx":1586
 * 
 * def write_baseq_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos',             # <<<<<<<<<<<<<<
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 * #                  'reads_pp', 'reads_pp_fwd', 'reads_pp_rev',
 */
  __pyx_k_tuple_37 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1586; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_37);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 2, ((PyObject *)__pyx_n_s__rms_baseq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 3, ((PyObject *)__pyx_n_s__rms_baseq_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 4, ((PyObject *)__pyx_n_s__rms_baseq_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 5, ((PyObject *)__pyx_n_s__rms_baseq_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 6, ((PyObject *)__pyx_n_s__rms_baseq_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_37, 7, ((PyObject *)__pyx_n_s__rms_baseq_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_37));

  /* "pysamstats.pyx":1702
 * 
 * def write_baseq_ext(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'ref',             # <<<<<<<<<<<<<<
 * #                  'reads_all', 'reads_pp',
 * #                  'matches', 'matches_pp',
 */
  __pyx_k_tuple_42 = PyTuple_New(9); if (unlikely(!__pyx_k_tuple_42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1702; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_42);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ref));
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 2, ((PyObject *)__pyx_n_s__ref));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ref));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq));
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 3, ((PyObject *)__pyx_n_s__rms_baseq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 4, ((PyObject *)__pyx_n_s__rms_baseq_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_matches));
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 5, ((PyObject *)__pyx_n_s__rms_baseq_matches));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_matches));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_38));
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 6, ((PyObject *)__pyx_n_s_38));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_38));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_39));
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 7, ((PyObject *)__pyx_n_s_39));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_39));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_40));
  PyTuple_SET_ITEM(__pyx_k_tuple_42, 8, ((PyObject *)__pyx_n_s_40));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_40));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_42));

  /* "pysamstats.pyx":1912
 * 
 * def write_baseq_ext_strand(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'ref',             # <<<<<<<<<<<<<<
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 * #                  'reads_pp', 'reads_pp_fwd', 'reads_pp_rev',
 */
  __pyx_k_tuple_52 = PyTuple_New(21); if (unlikely(!__pyx_k_tuple_52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1912; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_52);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ref));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 2, ((PyObject *)__pyx_n_s__ref));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ref));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 3, ((PyObject *)__pyx_n_s__rms_baseq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 4, ((PyObject *)__pyx_n_s__rms_baseq_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 5, ((PyObject *)__pyx_n_s__rms_baseq_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 6, ((PyObject *)__pyx_n_s__rms_baseq_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_pp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_pp_fwd));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 7, ((PyObject *)__pyx_n_s__rms_baseq_pp_fwd));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_pp_fwd));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_pp_rev));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 8, ((PyObject *)__pyx_n_s__rms_baseq_pp_rev));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_pp_rev));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rms_baseq_matches));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 9, ((PyObject *)__pyx_n_s__rms_baseq_matches));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rms_baseq_matches));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_43));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 10, ((PyObject *)__pyx_n_s_43));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_43));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_44));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 11, ((PyObject *)__pyx_n_s_44));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_44));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_38));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 12, ((PyObject *)__pyx_n_s_38));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_38));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_45));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 13, ((PyObject *)__pyx_n_s_45));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_45));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_46));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 14, ((PyObject *)__pyx_n_s_46));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_46));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_39));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 15, ((PyObject *)__pyx_n_s_39));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_39));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_47));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 16, ((PyObject *)__pyx_n_s_47));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_47));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_48));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 17, ((PyObject *)__pyx_n_s_48));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_48));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_40));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 18, ((PyObject *)__pyx_n_s_40));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_40));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_49));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 19, ((PyObject *)__pyx_n_s_49));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_49));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_50));
  PyTuple_SET_ITEM(__pyx_k_tuple_52, 20, ((PyObject *)__pyx_n_s_50));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_50));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_52));

  /* "pysamstats.pyx":1963
 * 
 * def write_coverage_normed(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'reads_all',             # <<<<<<<<<<<<<<
 *                   'dp_normed_median',
 *                   'dp_normed_mean',
 */
  __pyx_k_tuple_55 = PyTuple_New(6); if (unlikely(!__pyx_k_tuple_55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1963; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_55);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_55, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_55, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_55, 2, ((PyObject *)__pyx_n_s__reads_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_normed_median));
  PyTuple_SET_ITEM(__pyx_k_tuple_55, 3, ((PyObject *)__pyx_n_s__dp_normed_median));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_normed_median));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_normed_mean));
  PyTuple_SET_ITEM(__pyx_k_tuple_55, 4, ((PyObject *)__pyx_n_s__dp_normed_mean));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_normed_mean));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_percentile));
  PyTuple_SET_ITEM(__pyx_k_tuple_55, 5, ((PyObject *)__pyx_n_s__dp_percentile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_percentile));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_55));

  /* "pysamstats.pyx":2015
 * 
 * def write_coverage_gc(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'gc', 'reads_all', 'reads_pp')             # <<<<<<<<<<<<<<
 *     write_stats(stat_coverage_gc, fieldnames, *args, **kwargs)
 * 
 */
  __pyx_k_tuple_58 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_58)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2015; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_58);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_58, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_58, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gc));
  PyTuple_SET_ITEM(__pyx_k_tuple_58, 2, ((PyObject *)__pyx_n_s__gc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_58, 3, ((PyObject *)__pyx_n_s__reads_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_pp));
  PyTuple_SET_ITEM(__pyx_k_tuple_58, 4, ((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_pp));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_58));

  /* "pysamstats.pyx":2030
 *     recs = stat_coverage_gc(samfile, fafile, chrom=chrom, start=start, end=end, one_based=one_based)
 *     it = ((rec['reads_all'], rec['gc']) for rec in recs)
 *     a = np.fromiter(it, dtype=[('dp', 'u4'), ('gc', 'u1')]).view(np.recarray)             # <<<<<<<<<<<<<<
 *     dp_mean = np.mean(a.dp)
 *     dp_median = np.median(a.dp)
 */
  __pyx_k_tuple_60 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_60);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp));
  PyTuple_SET_ITEM(__pyx_k_tuple_60, 0, ((PyObject *)__pyx_n_s__dp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__u4));
  PyTuple_SET_ITEM(__pyx_k_tuple_60, 1, ((PyObject *)__pyx_n_s__u4));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__u4));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_60));
  __pyx_k_tuple_61 = PyTuple_New(2); if (unlikely(!__pyx_k_tuple_61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2030; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_61);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gc));
  PyTuple_SET_ITEM(__pyx_k_tuple_61, 0, ((PyObject *)__pyx_n_s__gc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__u1));
  PyTuple_SET_ITEM(__pyx_k_tuple_61, 1, ((PyObject *)__pyx_n_s__u1));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__u1));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_61));

  /* "pysamstats.pyx":2037
 *     dp_median_bygc = dict()
 *     dp_percentiles_bygc = dict()
 *     for gc in range(101):             # <<<<<<<<<<<<<<
 *         flt = a.gc == gc
 *         if np.count_nonzero(flt) > 0:
 */
  __pyx_k_tuple_62 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_62)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2037; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_62);
  __Pyx_INCREF(__pyx_int_101);
  PyTuple_SET_ITEM(__pyx_k_tuple_62, 0, __pyx_int_101);
  __Pyx_GIVEREF(__pyx_int_101);
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_62));

  /* "pysamstats.pyx":2067
 * 
 * def write_coverage_normed_gc(*args, **kwargs):
 *     fieldnames = ('chrom', 'pos', 'gc',             # <<<<<<<<<<<<<<
 *                   'reads_all', #'reads_pp',
 *                   'dp_normed_median',
 */
  __pyx_k_tuple_63 = PyTuple_New(10); if (unlikely(!__pyx_k_tuple_63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2067; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_63);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_63, 0, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_63, 1, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gc));
  PyTuple_SET_ITEM(__pyx_k_tuple_63, 2, ((PyObject *)__pyx_n_s__gc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__reads_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_63, 3, ((PyObject *)__pyx_n_s__reads_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__reads_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_normed_median));
  PyTuple_SET_ITEM(__pyx_k_tuple_63, 4, ((PyObject *)__pyx_n_s__dp_normed_median));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_normed_median));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_normed_mean));
  PyTuple_SET_ITEM(__pyx_k_tuple_63, 5, ((PyObject *)__pyx_n_s__dp_normed_mean));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_normed_mean));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_percentile));
  PyTuple_SET_ITEM(__pyx_k_tuple_63, 6, ((PyObject *)__pyx_n_s__dp_percentile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_percentile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_normed_median_gc));
  PyTuple_SET_ITEM(__pyx_k_tuple_63, 7, ((PyObject *)__pyx_n_s__dp_normed_median_gc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_normed_median_gc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_normed_mean_gc));
  PyTuple_SET_ITEM(__pyx_k_tuple_63, 8, ((PyObject *)__pyx_n_s__dp_normed_mean_gc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_normed_mean_gc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_percentile_gc));
  PyTuple_SET_ITEM(__pyx_k_tuple_63, 9, ((PyObject *)__pyx_n_s__dp_percentile_gc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_percentile_gc));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_63));

  /* "numpy.pxd":215
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
  __pyx_k_tuple_71 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_71)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_71);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_70));
  PyTuple_SET_ITEM(__pyx_k_tuple_71, 0, ((PyObject *)__pyx_kp_u_70));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_70));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_71));

  /* "numpy.pxd":219
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
  __pyx_k_tuple_73 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_73)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_73);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_72));
  PyTuple_SET_ITEM(__pyx_k_tuple_73, 0, ((PyObject *)__pyx_kp_u_72));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_72));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_73));

  /* "numpy.pxd":257
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
  __pyx_k_tuple_75 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_75)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 257; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_75);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_74));
  PyTuple_SET_ITEM(__pyx_k_tuple_75, 0, ((PyObject *)__pyx_kp_u_74));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_74));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_75));

  /* "numpy.pxd":799
 * 
 *         if (end - f) - (new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 */
  __pyx_k_tuple_78 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_78)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_78);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_77));
  PyTuple_SET_ITEM(__pyx_k_tuple_78, 0, ((PyObject *)__pyx_kp_u_77));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_77));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_78));

  /* "numpy.pxd":803
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
  __pyx_k_tuple_79 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_79)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_79);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_74));
  PyTuple_SET_ITEM(__pyx_k_tuple_79, 0, ((PyObject *)__pyx_kp_u_74));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_74));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_79));

  /* "numpy.pxd":823
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
  __pyx_k_tuple_81 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_81)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_81);
  __Pyx_INCREF(((PyObject *)__pyx_kp_u_80));
  PyTuple_SET_ITEM(__pyx_k_tuple_81, 0, ((PyObject *)__pyx_kp_u_80));
  __Pyx_GIVEREF(((PyObject *)__pyx_kp_u_80));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_81));

  /* "pysamstats.pyx":100
 * 
 * 
 * def stat_coverage(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_k_tuple_84 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_84)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_84);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_84, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_84, 1, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_84, 2, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_84, 3, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_84, 4, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_84, 5, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_84, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_84, 7, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_84));
  __pyx_k_codeobj_85 = (PyObject*)__Pyx_PyCode_New(5, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_84, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__stat_coverage, 100, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_85)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":106
 * 
 * 
 * def write_coverage(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'reads_all', 'reads_pp')
 *     write_stats(stat_coverage, fieldnames, *args, **kwargs)
 */
  __pyx_k_tuple_87 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_87)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_87);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_87, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_87, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_87, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_87, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_87, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_87));
  __pyx_k_codeobj_88 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_87, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_coverage, 106, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_88)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":169
 * 
 * 
 * def stat_coverage_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
  __pyx_k_tuple_89 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_89)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_89);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_89, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_89, 1, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_89, 2, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_89, 3, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_89, 4, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_89, 5, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_89, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_89, 7, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_89));
  __pyx_k_codeobj_90 = (PyObject*)__Pyx_PyCode_New(5, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_89, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_5, 169, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_90)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":175
 * 
 * 
 * def write_coverage_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all', 'reads_fwd', 'reads_rev',
 */
  __pyx_k_tuple_91 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_91)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_91);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_91, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_91, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_91, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_91, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_91, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_91));
  __pyx_k_codeobj_92 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_91, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_93, 175, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_92)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":256
 * 
 * 
 * def stat_coverage_ext(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
  __pyx_k_tuple_94 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_94)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_94);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_94, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_94, 1, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_94, 2, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_94, 3, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_94, 4, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_94, 5, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_94, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_94, 7, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_94));
  __pyx_k_codeobj_95 = (PyObject*)__Pyx_PyCode_New(5, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_94, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__stat_coverage_ext, 256, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_95)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":262
 * 
 * 
 * def write_coverage_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all',
 */
  __pyx_k_tuple_96 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_96)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_96);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_96, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_96, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_96, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_96, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_96, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_96));
  __pyx_k_codeobj_97 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_96, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_coverage_ext, 262, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_97)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":414
 * 
 * 
 * def stat_coverage_ext_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
  __pyx_k_tuple_98 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_98)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_98);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_98, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_98, 1, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_98, 2, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_98, 3, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_98, 4, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_98, 5, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_98, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_98, 7, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_98));
  __pyx_k_codeobj_99 = (PyObject*)__Pyx_PyCode_New(5, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_98, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_20, 414, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_99)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":420
 * 
 * 
 * def write_coverage_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all',
 */
  __pyx_k_tuple_100 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_100)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_100);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_100, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_100, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_100, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_100, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_100, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_100));
  __pyx_k_codeobj_101 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_100, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_102, 420, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_101)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":567
 * 
 * 
 * def stat_variation(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_k_tuple_103 = PyTuple_New(9); if (unlikely(!__pyx_k_tuple_103)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_103);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_103, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fafile));
  PyTuple_SET_ITEM(__pyx_k_tuple_103, 1, ((PyObject *)__pyx_n_s__fafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fafile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_103, 2, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_103, 3, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_103, 4, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_103, 5, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_103, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_103, 7, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_103, 8, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_103));
  __pyx_k_codeobj_104 = (PyObject*)__Pyx_PyCode_New(6, 0, 9, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_103, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__stat_variation, 567, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_104)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":573
 * 
 * 
 * def write_variation(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 *                   'reads_all', 'reads_pp',
 */
  __pyx_k_tuple_105 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_105)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_105);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_105, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_105, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_105, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_105, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_105, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_105));
  __pyx_k_codeobj_106 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_105, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_variation, 573, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_106)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":697
 * 
 * 
 * def stat_variation_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */
  __pyx_k_tuple_107 = PyTuple_New(9); if (unlikely(!__pyx_k_tuple_107)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_107);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_107, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fafile));
  PyTuple_SET_ITEM(__pyx_k_tuple_107, 1, ((PyObject *)__pyx_n_s__fafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fafile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_107, 2, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_107, 3, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_107, 4, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_107, 5, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_107, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_107, 7, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_107, 8, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_107));
  __pyx_k_codeobj_108 = (PyObject*)__Pyx_PyCode_New(6, 0, 9, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_107, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_25, 697, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_108)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":704
 * 
 * 
 * def write_variation_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 *                 'reads_all', 'reads_fwd', 'reads_rev', 'reads_pp', 'reads_pp_fwd', 'reads_pp_rev',
 */
  __pyx_k_tuple_109 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_109)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_109);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_109, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_109, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_109, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_109, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_109, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_109));
  __pyx_k_codeobj_110 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_109, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_111, 704, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_110)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":839
 * 
 * 
 * def stat_tlen(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_k_tuple_112 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_112)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_112);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_112, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_112, 1, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_112, 2, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_112, 3, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_112, 4, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_112, 5, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_112, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_112, 7, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_112));
  __pyx_k_codeobj_113 = (PyObject*)__Pyx_PyCode_New(5, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_112, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__stat_tlen, 839, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_113)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":845
 * 
 * 
 * def write_tlen(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *  #                 'reads_all', 'reads_paired', 'reads_pp',
 */
  __pyx_k_tuple_114 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_114)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_114);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_114, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_114, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_114, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_114, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_114, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_114));
  __pyx_k_codeobj_115 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_114, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_tlen, 845, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_115)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1096
 * 
 * 
 * def stat_tlen_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_k_tuple_116 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_116)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_116);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_116, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_116, 1, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_116, 2, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_116, 3, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_116, 4, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_116, 5, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_116, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_116, 7, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_116));
  __pyx_k_codeobj_117 = (PyObject*)__Pyx_PyCode_New(5, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_116, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__stat_tlen_strand, 1096, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_117)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1102
 * 
 * 
 * def write_tlen_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 */
  __pyx_k_tuple_118 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_118)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_118);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_118, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_118, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_118, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_118, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_118, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_118));
  __pyx_k_codeobj_119 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_118, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_tlen_strand, 1102, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_119)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1191
 * 
 * 
 * def stat_mapq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_k_tuple_120 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_120)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_120);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_120, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_120, 1, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_120, 2, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_120, 3, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_120, 4, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_120, 5, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_120, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_120, 7, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_120));
  __pyx_k_codeobj_121 = (PyObject*)__Pyx_PyCode_New(5, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_120, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__stat_mapq, 1191, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_121)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1197
 * 
 * 
 * def write_mapq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all', 'reads_pp',
 */
  __pyx_k_tuple_122 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_122)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_122);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_122, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_122, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_122, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_122, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_122, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_122));
  __pyx_k_codeobj_123 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_122, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_mapq, 1197, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_123)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1370
 * 
 * 
 * def stat_mapq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_k_tuple_124 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_124)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_124);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_124, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_124, 1, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_124, 2, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_124, 3, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_124, 4, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_124, 5, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_124, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_124, 7, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_124));
  __pyx_k_codeobj_125 = (PyObject*)__Pyx_PyCode_New(5, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_124, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__stat_mapq_strand, 1370, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_125)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1376
 * 
 * 
 * def write_mapq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all', 'reads_fwd', 'reads_rev',
 */
  __pyx_k_tuple_126 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_126)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_126);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_126, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_126, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_126, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_126, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_126, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_126));
  __pyx_k_codeobj_127 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_126, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_mapq_strand, 1376, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_127)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1450
 * 
 * 
 * def stat_baseq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_k_tuple_128 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_128)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_128);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_128, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_128, 1, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_128, 2, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_128, 3, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_128, 4, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_128, 5, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_128, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_128, 7, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_128));
  __pyx_k_codeobj_129 = (PyObject*)__Pyx_PyCode_New(5, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_128, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__stat_baseq, 1450, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_129)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1456
 * 
 * 
 * def write_baseq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 * #                  'reads_all',
 */
  __pyx_k_tuple_130 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_130)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_130);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_130, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_130, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_130, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_130, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_130, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_130));
  __pyx_k_codeobj_131 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_130, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_baseq, 1456, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_131)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1579
 * 
 * 
 * def stat_baseq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_k_tuple_132 = PyTuple_New(8); if (unlikely(!__pyx_k_tuple_132)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_132);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_132, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_132, 1, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_132, 2, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_132, 3, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_132, 4, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_132, 5, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_132, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_132, 7, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_132));
  __pyx_k_codeobj_133 = (PyObject*)__Pyx_PyCode_New(5, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_132, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__stat_baseq_strand, 1579, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_133)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1585
 * 
 * 
 * def write_baseq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 */
  __pyx_k_tuple_134 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_134)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_134);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_134, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_134, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_134, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_134, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_134, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_134));
  __pyx_k_codeobj_135 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_134, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_baseq_strand, 1585, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_135)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1694
 * 
 * 
 * def stat_baseq_ext(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                    chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */
  __pyx_k_tuple_136 = PyTuple_New(9); if (unlikely(!__pyx_k_tuple_136)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_136);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_136, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fafile));
  PyTuple_SET_ITEM(__pyx_k_tuple_136, 1, ((PyObject *)__pyx_n_s__fafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fafile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_136, 2, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_136, 3, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_136, 4, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_136, 5, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_136, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_136, 7, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_136, 8, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_136));
  __pyx_k_codeobj_137 = (PyObject*)__Pyx_PyCode_New(6, 0, 9, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_136, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__stat_baseq_ext, 1694, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_137)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1701
 * 
 * 
 * def write_baseq_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 * #                  'reads_all', 'reads_pp',
 */
  __pyx_k_tuple_138 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_138)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_138);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_138, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_138, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_138, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_138, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_138, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_138));
  __pyx_k_codeobj_139 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_138, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_baseq_ext, 1701, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_139)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1904
 * 
 * 
 * def stat_baseq_ext_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */
  __pyx_k_tuple_140 = PyTuple_New(9); if (unlikely(!__pyx_k_tuple_140)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_140);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_140, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fafile));
  PyTuple_SET_ITEM(__pyx_k_tuple_140, 1, ((PyObject *)__pyx_n_s__fafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fafile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_140, 2, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_140, 3, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_140, 4, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_140, 5, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_140, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_140, 7, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_140, 8, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_140));
  __pyx_k_codeobj_141 = (PyObject*)__Pyx_PyCode_New(6, 0, 9, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_140, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_53, 1904, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_141)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1911
 * 
 * 
 * def write_baseq_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 */
  __pyx_k_tuple_142 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_142)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_142);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_142, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_142, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_142, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_142, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_142, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_142));
  __pyx_k_codeobj_143 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_142, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_144, 1911, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_143)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1937
 * 
 * 
 * def stat_coverage_normed(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 * 
 */
  __pyx_k_tuple_145 = PyTuple_New(21); if (unlikely(!__pyx_k_tuple_145)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_145);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 1, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 2, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 3, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 4, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 5, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__it));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 7, ((PyObject *)__pyx_n_s__it));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__it));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__a));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 8, ((PyObject *)__pyx_n_s__a));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__a));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_mean));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 9, ((PyObject *)__pyx_n_s__dp_mean));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_mean));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_median));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 10, ((PyObject *)__pyx_n_s__dp_median));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_median));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_percentiles));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 11, ((PyObject *)__pyx_n_s__dp_percentiles));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_percentiles));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 12, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__pos));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 13, ((PyObject *)__pyx_n_s__pos));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__pos));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 14, ((PyObject *)__pyx_n_s__dp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_normed_median));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 15, ((PyObject *)__pyx_n_s__dp_normed_median));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_normed_median));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_normed_mean));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 16, ((PyObject *)__pyx_n_s__dp_normed_mean));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_normed_mean));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_percentile));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 17, ((PyObject *)__pyx_n_s__dp_percentile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_percentile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 18, ((PyObject *)__pyx_n_s__genexpr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 19, ((PyObject *)__pyx_n_s__genexpr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__q));
  PyTuple_SET_ITEM(__pyx_k_tuple_145, 20, ((PyObject *)__pyx_n_s__q));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__q));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_145));
  __pyx_k_codeobj_146 = (PyObject*)__Pyx_PyCode_New(5, 0, 21, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_145, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_56, 1937, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_146)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1962
 * 
 * 
 * def write_coverage_normed(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'reads_all',
 *                   'dp_normed_median',
 */
  __pyx_k_tuple_147 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_147)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_147);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_147, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_147, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_147, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_147, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_147, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_147));
  __pyx_k_codeobj_148 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_147, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_149, 1962, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_148)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":1978
 * 
 * 
 * def stat_coverage_gc(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                      chrom=None, start=None, end=None, one_based=False,
 *                      gc_window_length=300, gc_window_offset=150, **kwargs):
 */
  __pyx_k_tuple_150 = PyTuple_New(20); if (unlikely(!__pyx_k_tuple_150)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_150);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fafile));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 1, ((PyObject *)__pyx_n_s__fafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fafile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 2, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 3, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 4, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 5, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gc_window_length));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 6, ((PyObject *)__pyx_n_s__gc_window_length));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gc_window_length));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gc_window_offset));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 7, ((PyObject *)__pyx_n_s__gc_window_offset));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gc_window_offset));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 8, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 9, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__i));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 10, ((PyObject *)__pyx_n_s__i));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__i));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__seq));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 11, ((PyObject *)__pyx_n_s__seq));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__seq));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gc_count));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 12, ((PyObject *)__pyx_n_s__gc_count));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gc_count));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__col));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 13, ((PyObject *)__pyx_n_s__col));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__col));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ref_window_start));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 14, ((PyObject *)__pyx_n_s__ref_window_start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ref_window_start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ref_window_end));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 15, ((PyObject *)__pyx_n_s__ref_window_end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ref_window_end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__ref_window));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 16, ((PyObject *)__pyx_n_s__ref_window));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__ref_window));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__b));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 17, ((PyObject *)__pyx_n_s__b));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__b));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gc_percent));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 18, ((PyObject *)__pyx_n_s__gc_percent));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gc_percent));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rec));
  PyTuple_SET_ITEM(__pyx_k_tuple_150, 19, ((PyObject *)__pyx_n_s__rec));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rec));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_150));
  __pyx_k_codeobj_151 = (PyObject*)__Pyx_PyCode_New(8, 0, 20, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_150, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__stat_coverage_gc, 1978, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_151)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2014
 * 
 * 
 * def write_coverage_gc(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'gc', 'reads_all', 'reads_pp')
 *     write_stats(stat_coverage_gc, fieldnames, *args, **kwargs)
 */
  __pyx_k_tuple_152 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_152)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_152);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_152, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_152, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_152, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_152, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_152, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_152));
  __pyx_k_codeobj_153 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_152, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_coverage_gc, 2014, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_153)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2024
 * 
 * 
 * def stat_coverage_normed_gc(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 * 
 */
  __pyx_k_tuple_155 = PyTuple_New(31); if (unlikely(!__pyx_k_tuple_155)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_155);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 0, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fafile));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 1, ((PyObject *)__pyx_n_s__fafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fafile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 2, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 3, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 4, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 5, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 6, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 7, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__recs));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 8, ((PyObject *)__pyx_n_s__recs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__recs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__it));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 9, ((PyObject *)__pyx_n_s__it));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__it));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__a));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 10, ((PyObject *)__pyx_n_s__a));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__a));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_mean));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 11, ((PyObject *)__pyx_n_s__dp_mean));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_mean));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_median));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 12, ((PyObject *)__pyx_n_s__dp_median));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_median));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_percentiles));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 13, ((PyObject *)__pyx_n_s__dp_percentiles));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_percentiles));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_mean_bygc));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 14, ((PyObject *)__pyx_n_s__dp_mean_bygc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_mean_bygc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_median_bygc));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 15, ((PyObject *)__pyx_n_s__dp_median_bygc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_median_bygc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_percentiles_bygc));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 16, ((PyObject *)__pyx_n_s__dp_percentiles_bygc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_percentiles_bygc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__gc));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 17, ((PyObject *)__pyx_n_s__gc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__gc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__flt));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 18, ((PyObject *)__pyx_n_s__flt));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__flt));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__b));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 19, ((PyObject *)__pyx_n_s__b));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__b));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rec));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 20, ((PyObject *)__pyx_n_s__rec));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rec));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 21, ((PyObject *)__pyx_n_s__dp));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_normed_median));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 22, ((PyObject *)__pyx_n_s__dp_normed_median));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_normed_median));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_normed_mean));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 23, ((PyObject *)__pyx_n_s__dp_normed_mean));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_normed_mean));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_percentile));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 24, ((PyObject *)__pyx_n_s__dp_percentile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_percentile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s_154));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 25, ((PyObject *)__pyx_n_s_154));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s_154));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_normed_mean_bygc));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 26, ((PyObject *)__pyx_n_s__dp_normed_mean_bygc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_normed_mean_bygc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dp_percentile_bygc));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 27, ((PyObject *)__pyx_n_s__dp_percentile_bygc));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dp_percentile_bygc));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 28, ((PyObject *)__pyx_n_s__genexpr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__genexpr));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 29, ((PyObject *)__pyx_n_s__genexpr));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__genexpr));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__q));
  PyTuple_SET_ITEM(__pyx_k_tuple_155, 30, ((PyObject *)__pyx_n_s__q));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__q));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_155));
  __pyx_k_codeobj_156 = (PyObject*)__Pyx_PyCode_New(6, 0, 31, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_155, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_64, 2024, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_156)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2066
 * 
 * 
 * def write_coverage_normed_gc(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'gc',
 *                   'reads_all', #'reads_pp',
 */
  __pyx_k_tuple_157 = PyTuple_New(5); if (unlikely(!__pyx_k_tuple_157)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_157);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_157, 0, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_157, 1, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__args));
  PyTuple_SET_ITEM(__pyx_k_tuple_157, 2, ((PyObject *)__pyx_n_s__args));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__args));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_157, 3, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_157, 4, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_157));
  __pyx_k_codeobj_158 = (PyObject*)__Pyx_PyCode_New(0, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_157, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s_159, 2066, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_158)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2083
 * 
 * 
 * def normalise_coords(start, end, one_based):             # <<<<<<<<<<<<<<
 *     if one_based:
 *         start = start - 1 if start is not None else None
 */
  __pyx_k_tuple_160 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_160)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_160);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_160, 0, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_160, 1, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_160, 2, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_160));
  __pyx_k_codeobj_161 = (PyObject*)__Pyx_PyCode_New(3, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_160, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__normalise_coords, 2083, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_161)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":2090
 * 
 * 
 * def write_stats(statfun, fieldnames, outfile, samfile, fafile=None,             # <<<<<<<<<<<<<<
 *                 dialect=csv.excel_tab, write_header=True,
 *                 chrom=None, start=None, end=None,
 */
  __pyx_k_tuple_162 = PyTuple_New(26); if (unlikely(!__pyx_k_tuple_162)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_k_tuple_162);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__statfun));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 0, ((PyObject *)__pyx_n_s__statfun));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__statfun));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fieldnames));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 1, ((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fieldnames));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__outfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 2, ((PyObject *)__pyx_n_s__outfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__outfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__samfile));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 3, ((PyObject *)__pyx_n_s__samfile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__samfile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__fafile));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 4, ((PyObject *)__pyx_n_s__fafile));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__fafile));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__dialect));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 5, ((PyObject *)__pyx_n_s__dialect));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__dialect));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__write_header));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 6, ((PyObject *)__pyx_n_s__write_header));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__write_header));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__chrom));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 7, ((PyObject *)__pyx_n_s__chrom));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__chrom));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__start));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 8, ((PyObject *)__pyx_n_s__start));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__start));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__end));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 9, ((PyObject *)__pyx_n_s__end));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__end));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__one_based));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 10, ((PyObject *)__pyx_n_s__one_based));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__one_based));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__progress));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 11, ((PyObject *)__pyx_n_s__progress));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__progress));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 12, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__kwargs));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 13, ((PyObject *)__pyx_n_s__kwargs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__kwargs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__counter));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 14, ((PyObject *)__pyx_n_s__counter));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__counter));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__modulus));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 15, ((PyObject *)__pyx_n_s__modulus));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__modulus));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__writer));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 16, ((PyObject *)__pyx_n_s__writer));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__writer));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__recs));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 17, ((PyObject *)__pyx_n_s__recs));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__recs));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__before));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 18, ((PyObject *)__pyx_n_s__before));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__before));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__before_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 19, ((PyObject *)__pyx_n_s__before_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__before_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__rec));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 20, ((PyObject *)__pyx_n_s__rec));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__rec));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__after));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 21, ((PyObject *)__pyx_n_s__after));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__after));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__elapsed));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 22, ((PyObject *)__pyx_n_s__elapsed));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__elapsed));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__batch_elapsed));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 23, ((PyObject *)__pyx_n_s__batch_elapsed));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__batch_elapsed));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__after_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 24, ((PyObject *)__pyx_n_s__after_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__after_all));
  __Pyx_INCREF(((PyObject *)__pyx_n_s__elapsed_all));
  PyTuple_SET_ITEM(__pyx_k_tuple_162, 25, ((PyObject *)__pyx_n_s__elapsed_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__elapsed_all));
  __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_162));
  __pyx_k_codeobj_163 = (PyObject*)__Pyx_PyCode_New(12, 0, 26, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_k_tuple_162, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_86, __pyx_n_s__write_stats, 2090, __pyx_empty_bytes); if (unlikely(!__pyx_k_codeobj_163)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __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_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_101 = PyInt_FromLong(101); if (unlikely(!__pyx_int_101)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_150 = PyInt_FromLong(150); if (unlikely(!__pyx_int_150)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_int_300 = PyInt_FromLong(300); if (unlikely(!__pyx_int_300)) {__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 initpysamstats(void); /*proto*/
PyMODINIT_FUNC initpysamstats(void)
#else
PyMODINIT_FUNC PyInit_pysamstats(void); /*proto*/
PyMODINIT_FUNC PyInit_pysamstats(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __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_pysamstats(void)", 0);
  if ( __Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __Pyx_CyFunction_USED
  if (__Pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4(__Pyx_NAMESTR("pysamstats"), __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;}
  #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, "pysamstats")) {
      if (unlikely(PyDict_SetItemString(modules, "pysamstats", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif
  __pyx_b = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (__Pyx_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (unlikely(__Pyx_InitGlobals() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_module_is_main_pysamstats) {
    if (__Pyx_SetAttrString(__pyx_m, "__name__", __pyx_n_s____main__) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  }
  /*--- Builtin init code ---*/
  if (unlikely(__Pyx_InitCachedBuiltins() < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- 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 ---*/
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct__stat_coverage) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct__stat_coverage = &__pyx_type_10pysamstats___pyx_scope_struct__stat_coverage;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_1_stat_coverage_strand) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_1_stat_coverage_strand = &__pyx_type_10pysamstats___pyx_scope_struct_1_stat_coverage_strand;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_2_stat_coverage_ext) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_2_stat_coverage_ext = &__pyx_type_10pysamstats___pyx_scope_struct_2_stat_coverage_ext;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand = &__pyx_type_10pysamstats___pyx_scope_struct_3_stat_coverage_ext_strand;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_4_stat_variation) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_4_stat_variation = &__pyx_type_10pysamstats___pyx_scope_struct_4_stat_variation;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_5_stat_variation_strand) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_5_stat_variation_strand = &__pyx_type_10pysamstats___pyx_scope_struct_5_stat_variation_strand;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_6_stat_tlen) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_6_stat_tlen = &__pyx_type_10pysamstats___pyx_scope_struct_6_stat_tlen;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_7_stat_tlen_strand) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_7_stat_tlen_strand = &__pyx_type_10pysamstats___pyx_scope_struct_7_stat_tlen_strand;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_8_stat_mapq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_8_stat_mapq = &__pyx_type_10pysamstats___pyx_scope_struct_8_stat_mapq;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_9_stat_mapq_strand) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_9_stat_mapq_strand = &__pyx_type_10pysamstats___pyx_scope_struct_9_stat_mapq_strand;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_10_stat_baseq) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_10_stat_baseq = &__pyx_type_10pysamstats___pyx_scope_struct_10_stat_baseq;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_11_stat_baseq_strand) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_11_stat_baseq_strand = &__pyx_type_10pysamstats___pyx_scope_struct_11_stat_baseq_strand;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_12_stat_baseq_ext) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_12_stat_baseq_ext = &__pyx_type_10pysamstats___pyx_scope_struct_12_stat_baseq_ext;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand = &__pyx_type_10pysamstats___pyx_scope_struct_13_stat_baseq_ext_strand;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_14_stat_coverage_normed) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_14_stat_coverage_normed = &__pyx_type_10pysamstats___pyx_scope_struct_14_stat_coverage_normed;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_15_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_15_genexpr = &__pyx_type_10pysamstats___pyx_scope_struct_15_genexpr;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_16_stat_coverage_gc) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_16_stat_coverage_gc = &__pyx_type_10pysamstats___pyx_scope_struct_16_stat_coverage_gc;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc = &__pyx_type_10pysamstats___pyx_scope_struct_17_stat_coverage_normed_gc;
  if (PyType_Ready(&__pyx_type_10pysamstats___pyx_scope_struct_18_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2029; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_10pysamstats___pyx_scope_struct_18_genexpr = &__pyx_type_10pysamstats___pyx_scope_struct_18_genexpr;
  /*--- Type import code ---*/
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if CYTHON_COMPILING_IN_PYPY
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_5numpy_dtype)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_flatiter)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_broadcast)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_5numpy_ndarray)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_ufunc = __Pyx_ImportType("numpy", "ufunc", sizeof(PyUFuncObject), 0); if (unlikely(!__pyx_ptype_5numpy_ufunc)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_4bool_bool = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "bool", sizeof(PyBoolObject), 0); if (unlikely(!__pyx_ptype_7cpython_4bool_bool)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_7cpython_7complex_complex = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "complex", sizeof(PyComplexObject), 0); if (unlikely(!__pyx_ptype_7cpython_7complex_complex)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_Fastafile = __Pyx_ImportType("pysam.csamtools", "Fastafile", sizeof(struct __pyx_obj_5pysam_9csamtools_Fastafile), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_Fastafile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_9csamtools_Fastafile = (struct __pyx_vtabstruct_5pysam_9csamtools_Fastafile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9csamtools_Fastafile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9csamtools_Fastafile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 408; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_AlignedRead = __Pyx_ImportType("pysam.csamtools", "AlignedRead", sizeof(struct __pyx_obj_5pysam_9csamtools_AlignedRead), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_AlignedRead)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 415; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_Samfile = __Pyx_ImportType("pysam.csamtools", "Samfile", sizeof(struct __pyx_obj_5pysam_9csamtools_Samfile), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_Samfile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_9csamtools_Samfile = (struct __pyx_vtabstruct_5pysam_9csamtools_Samfile*)__Pyx_GetVtable(__pyx_ptype_5pysam_9csamtools_Samfile->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9csamtools_Samfile)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_PileupProxy = __Pyx_ImportType("pysam.csamtools", "PileupProxy", sizeof(struct __pyx_obj_5pysam_9csamtools_PileupProxy), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_PileupProxy)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 449; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_PileupRead = __Pyx_ImportType("pysam.csamtools", "PileupRead", sizeof(struct __pyx_obj_5pysam_9csamtools_PileupRead), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_PileupRead)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 455; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_IteratorRow = __Pyx_ImportType("pysam.csamtools", "IteratorRow", sizeof(struct __pyx_obj_5pysam_9csamtools_IteratorRow), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_IteratorRow)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 464; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_IteratorRowRegion = __Pyx_ImportType("pysam.csamtools", "IteratorRowRegion", sizeof(struct __pyx_obj_5pysam_9csamtools_IteratorRowRegion), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_IteratorRowRegion)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_9csamtools_IteratorRowRegion = (struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_9csamtools_IteratorRowRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9csamtools_IteratorRowRegion)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 467; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_IteratorRowAll = __Pyx_ImportType("pysam.csamtools", "IteratorRowAll", sizeof(struct __pyx_obj_5pysam_9csamtools_IteratorRowAll), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_IteratorRowAll)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_9csamtools_IteratorRowAll = (struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowAll*)__Pyx_GetVtable(__pyx_ptype_5pysam_9csamtools_IteratorRowAll->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9csamtools_IteratorRowAll)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 480; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_IteratorRowAllRefs = __Pyx_ImportType("pysam.csamtools", "IteratorRowAllRefs", sizeof(struct __pyx_obj_5pysam_9csamtools_IteratorRowAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_IteratorRowAllRefs)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_IteratorRowSelection = __Pyx_ImportType("pysam.csamtools", "IteratorRowSelection", sizeof(struct __pyx_obj_5pysam_9csamtools_IteratorRowSelection), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_IteratorRowSelection)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_9csamtools_IteratorRowSelection = (struct __pyx_vtabstruct_5pysam_9csamtools_IteratorRowSelection*)__Pyx_GetVtable(__pyx_ptype_5pysam_9csamtools_IteratorRowSelection->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9csamtools_IteratorRowSelection)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 492; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_IteratorColumn = __Pyx_ImportType("pysam.csamtools", "IteratorColumn", sizeof(struct __pyx_obj_5pysam_9csamtools_IteratorColumn), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_IteratorColumn)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_9csamtools_IteratorColumn = (struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumn*)__Pyx_GetVtable(__pyx_ptype_5pysam_9csamtools_IteratorColumn->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9csamtools_IteratorColumn)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 504; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_IteratorColumnRegion = __Pyx_ImportType("pysam.csamtools", "IteratorColumnRegion", sizeof(struct __pyx_obj_5pysam_9csamtools_IteratorColumnRegion), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_IteratorColumnRegion)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_9csamtools_IteratorColumnRegion = (struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnRegion*)__Pyx_GetVtable(__pyx_ptype_5pysam_9csamtools_IteratorColumnRegion->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9csamtools_IteratorColumnRegion)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_IteratorColumnAllRefs = __Pyx_ImportType("pysam.csamtools", "IteratorColumnAllRefs", sizeof(struct __pyx_obj_5pysam_9csamtools_IteratorColumnAllRefs), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_IteratorColumnAllRefs)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_vtabptr_5pysam_9csamtools_IteratorColumnAllRefs = (struct __pyx_vtabstruct_5pysam_9csamtools_IteratorColumnAllRefs*)__Pyx_GetVtable(__pyx_ptype_5pysam_9csamtools_IteratorColumnAllRefs->tp_dict); if (unlikely(!__pyx_vtabptr_5pysam_9csamtools_IteratorColumnAllRefs)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 536; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5pysam_9csamtools_IndexedReads = __Pyx_ImportType("pysam.csamtools", "IndexedReads", sizeof(struct __pyx_obj_5pysam_9csamtools_IndexedReads), 1); if (unlikely(!__pyx_ptype_5pysam_9csamtools_IndexedReads)) {__pyx_filename = __pyx_f[5]; __pyx_lineno = 539; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/

  /* "pysamstats.pyx":4
 * 
 * 
 * __version__ = '0.4.5'             # <<<<<<<<<<<<<<
 * 
 * 
 */
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____version__, ((PyObject *)__pyx_kp_s_82)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "pysamstats.pyx":7
 * 
 * 
 * import sys             # <<<<<<<<<<<<<<
 * import numpy as np
 * cimport numpy as np
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__sys), 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 (PyObject_SetAttr(__pyx_m, __pyx_n_s__sys, __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;

  /* "pysamstats.pyx":8
 * 
 * import sys
 * import numpy as np             # <<<<<<<<<<<<<<
 * cimport numpy as np
 * import time
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 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 (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __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;

  /* "pysamstats.pyx":10
 * import numpy as np
 * cimport numpy as np
 * import time             # <<<<<<<<<<<<<<
 * import csv
 * from libc.stdint cimport uint32_t, uint8_t, uint64_t, int64_t
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__time), 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 (PyObject_SetAttr(__pyx_m, __pyx_n_s__time, __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;

  /* "pysamstats.pyx":11
 * cimport numpy as np
 * import time
 * import csv             # <<<<<<<<<<<<<<
 * from libc.stdint cimport uint32_t, uint8_t, uint64_t, int64_t
 * from libc.math cimport sqrt
 */
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__csv), 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 (PyObject_SetAttr(__pyx_m, __pyx_n_s__csv, __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;

  /* "pysamstats.pyx":57
 * DEF BAM_CDIFF      = 8
 * 
 * cdef char * bam_nt16_rev_table = "=ACMGRSVTWYHKDBN"             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_v_10pysamstats_bam_nt16_rev_table = __pyx_k_83;

  /* "pysamstats.pyx":100
 * 
 * 
 * def stat_coverage(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_1 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_3stat_coverage, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__stat_coverage, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":106
 * 
 * 
 * def write_coverage(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'reads_all', 'reads_pp')
 *     write_stats(stat_coverage, fieldnames, *args, **kwargs)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_6write_coverage, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_coverage, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":169
 * 
 * 
 * def stat_coverage_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_3 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_10stat_coverage_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_5, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":175
 * 
 * 
 * def write_coverage_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all', 'reads_fwd', 'reads_rev',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_13write_coverage_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_93, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":256
 * 
 * 
 * def stat_coverage_ext(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_8 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_17stat_coverage_ext, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__stat_coverage_ext, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":262
 * 
 * 
 * def write_coverage_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_20write_coverage_ext, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_coverage_ext, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 262; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":414
 * 
 * 
 * def stat_coverage_ext_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(chrom, start, end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_18 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_24stat_coverage_ext_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_20, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 414; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":420
 * 
 * 
 * def write_coverage_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_27write_coverage_ext_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_102, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 420; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":567
 * 
 * 
 * def stat_variation(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_21 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_31stat_variation, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__stat_variation, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 567; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":573
 * 
 * 
 * def write_variation(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 *                   'reads_all', 'reads_pp',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_34write_variation, NULL, __pyx_n_s__pysamstats); 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);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_variation, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":698
 * 
 * def stat_variation_strand(Samfile samfile, Fastafile fafile,
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_23 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":697
 * 
 * 
 * def stat_variation_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_38stat_variation_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_25, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 697; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":704
 * 
 * 
 * def write_variation_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 *                 'reads_all', 'reads_fwd', 'reads_rev', 'reads_pp', 'reads_pp_fwd', 'reads_pp_rev',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_41write_variation_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_111, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 704; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":839
 * 
 * 
 * def stat_tlen(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_26 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_45stat_tlen, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__stat_tlen, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":845
 * 
 * 
 * def write_tlen(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *  #                 'reads_all', 'reads_paired', 'reads_pp',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_48write_tlen, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_tlen, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 845; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1096
 * 
 * 
 * def stat_tlen_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_28 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_52stat_tlen_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__stat_tlen_strand, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1096; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1102
 * 
 * 
 * def write_tlen_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_55write_tlen_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_tlen_strand, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1102; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1191
 * 
 * 
 * def stat_mapq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_30 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_59stat_mapq, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__stat_mapq, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1191; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1197
 * 
 * 
 * def write_mapq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all', 'reads_pp',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_62write_mapq, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_mapq, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1197; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1370
 * 
 * 
 * def stat_mapq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_32 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_66stat_mapq_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__stat_mapq_strand, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1370; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1376
 * 
 * 
 * def write_mapq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 *                   'reads_all', 'reads_fwd', 'reads_rev',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_69write_mapq_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_mapq_strand, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1376; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1450
 * 
 * 
 * def stat_baseq(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_34 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_73stat_baseq, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__stat_baseq, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1456
 * 
 * 
 * def write_baseq(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 * #                  'reads_all',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_76write_baseq, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_baseq, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1456; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1579
 * 
 * 
 * def stat_baseq_strand(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_36 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_80stat_baseq_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__stat_baseq_strand, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1585
 * 
 * 
 * def write_baseq_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos',
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_83write_baseq_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_baseq_strand, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1585; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1695
 * 
 * def stat_baseq_ext(Samfile samfile, Fastafile fafile,
 *                    chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1695; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_41 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1694
 * 
 * 
 * def stat_baseq_ext(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                    chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_87stat_baseq_ext, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__stat_baseq_ext, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1701
 * 
 * 
 * def write_baseq_ext(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 * #                  'reads_all', 'reads_pp',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_90write_baseq_ext, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_baseq_ext, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1701; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1905
 * 
 * def stat_baseq_ext_strand(Samfile samfile, Fastafile fafile,
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 *     for col in samfile.pileup(reference=chrom, start=start, end=end):
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1905; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_51 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1904
 * 
 * 
 * def stat_baseq_ext_strand(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                           chrom=None, start=None, end=None, one_based=False, **kwargs):
 *     start, end = normalise_coords(start, end, one_based)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_94stat_baseq_ext_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_53, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1904; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1911
 * 
 * 
 * def write_baseq_ext_strand(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'ref',
 * #                  'reads_all', 'reads_fwd', 'reads_rev',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_97write_baseq_ext_strand, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_144, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1934
 * 
 * 
 * from bisect import bisect_left             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__bisect_left));
  PyList_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_n_s__bisect_left));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__bisect_left));
  __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s__bisect), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__bisect_left);
  if (__pyx_t_1 == NULL) {
    if (PyErr_ExceptionMatches(PyExc_AttributeError)) __Pyx_RaiseImportError(__pyx_n_s__bisect_left);
    if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__bisect_left, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1937
 * 
 * 
 * def stat_coverage_normed(Samfile samfile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 * 
 */
  __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_k_54 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_99stat_coverage_normed, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_56, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1962
 * 
 * 
 * def write_coverage_normed(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'reads_all',
 *                   'dp_normed_median',
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_102write_coverage_normed, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_149, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1962; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1975
 * 
 * 
 * from collections import Counter             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(((PyObject *)__pyx_n_s__Counter));
  PyList_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_n_s__Counter));
  __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Counter));
  __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__collections), ((PyObject *)__pyx_t_2), -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__Counter);
  if (__pyx_t_2 == NULL) {
    if (PyErr_ExceptionMatches(PyExc_AttributeError)) __Pyx_RaiseImportError(__pyx_n_s__Counter);
    if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Counter, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1975; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":1979
 * 
 * def stat_coverage_gc(Samfile samfile, Fastafile fafile,
 *                      chrom=None, start=None, end=None, one_based=False,             # <<<<<<<<<<<<<<
 *                      gc_window_length=300, gc_window_offset=150, **kwargs):
 *     cdef Py_ssize_t i # loop index
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_57 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "pysamstats.pyx":1978
 * 
 * 
 * def stat_coverage_gc(Samfile samfile, Fastafile fafile,             # <<<<<<<<<<<<<<
 *                      chrom=None, start=None, end=None, one_based=False,
 *                      gc_window_length=300, gc_window_offset=150, **kwargs):
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_104stat_coverage_gc, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__stat_coverage_gc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2014
 * 
 * 
 * def write_coverage_gc(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'gc', 'reads_all', 'reads_pp')
 *     write_stats(stat_coverage_gc, fieldnames, *args, **kwargs)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_107write_coverage_gc, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_coverage_gc, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2014; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2024
 * 
 * 
 * def stat_coverage_normed_gc(Samfile samfile, Fastafile fafile, chrom=None, start=None, end=None, one_based=False, **kwargs):             # <<<<<<<<<<<<<<
 *     start, end = normalise_coords(start, end, one_based)
 * 
 */
  __pyx_t_1 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_k_59 = __pyx_t_1;
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_109stat_coverage_normed_gc, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_64, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2024; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2066
 * 
 * 
 * def write_coverage_normed_gc(*args, **kwargs):             # <<<<<<<<<<<<<<
 *     fieldnames = ('chrom', 'pos', 'gc',
 *                   'reads_all', #'reads_pp',
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_112write_coverage_normed_gc, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s_159, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2066; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2083
 * 
 * 
 * def normalise_coords(start, end, one_based):             # <<<<<<<<<<<<<<
 *     if one_based:
 *         start = start - 1 if start is not None else None
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_114normalise_coords, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__normalise_coords, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "pysamstats.pyx":2091
 * 
 * def write_stats(statfun, fieldnames, outfile, samfile, fafile=None,
 *                 dialect=csv.excel_tab, write_header=True,             # <<<<<<<<<<<<<<
 *                 chrom=None, start=None, end=None,
 *                 one_based=False, progress=None, **kwargs):
 */
  __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__csv); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__excel_tab); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_k_65 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyBool_FromLong(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_k_66 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":2093
 *                 dialect=csv.excel_tab, write_header=True,
 *                 chrom=None, start=None, end=None,
 *                 one_based=False, progress=None, **kwargs):             # <<<<<<<<<<<<<<
 *     cdef long long counter = 0
 *     cdef long long modulus
 */
  __pyx_t_2 = __Pyx_PyBool_FromLong(0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2093; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_k_67 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;

  /* "pysamstats.pyx":2090
 * 
 * 
 * def write_stats(statfun, fieldnames, outfile, samfile, fafile=None,             # <<<<<<<<<<<<<<
 *                 dialect=csv.excel_tab, write_header=True,
 *                 chrom=None, start=None, end=None,
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_10pysamstats_116write_stats, NULL, __pyx_n_s__pysamstats); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s__write_stats, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2090; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "pysamstats.pyx":1
 * # cython: profile=False             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(((PyObject *)__pyx_t_2));
  if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_2)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0;

  /* "numpy.pxd":975
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  if (__pyx_m) {
    __Pyx_AddTraceback("init pysamstats", __pyx_clineno, __pyx_lineno, __pyx_filename);
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init pysamstats");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* Runtime support code */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif /* CYTHON_REFNANNY */

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result) {
        if (dict != __pyx_b) {
            PyErr_Clear();
            result = PyObject_GetAttr(__pyx_b, name);
        }
        if (!result) {
            PyErr_SetObject(PyExc_NameError, name);
        }
    }
    return result;
}

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,
                 "%s() takes %s %" CYTHON_FORMAT_SSIZE_T "d positional argument%s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

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,
        "%s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (!type) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (Py_TYPE(obj) == type) return 1;
    }
    else {
        if (PyObject_TypeCheck(obj, type)) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%s' has incorrect type (expected %s, got %s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}

static CYTHON_INLINE void __Pyx_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%s 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 CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

static CYTHON_INLINE int __Pyx_CheckKeywordStrings(
    PyObject *kwdict,
    const char* function_name,
    int kw_allowed)
{
    PyObject* key = 0;
    Py_ssize_t pos = 0;
#if CPYTHON_COMPILING_IN_PYPY
    if (!kw_allowed && PyDict_Next(kwdict, &pos, &key, 0))
        goto invalid_keyword;
    return 1;
#else
    while (PyDict_Next(kwdict, &pos, &key, 0)) {
        #if PY_MAJOR_VERSION < 3
        if (unlikely(!PyString_CheckExact(key)) && unlikely(!PyString_Check(key)))
        #endif
            if (unlikely(!PyUnicode_Check(key)))
                goto invalid_keyword_type;
    }
    if ((!kw_allowed) && unlikely(key))
        goto invalid_keyword;
    return 1;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%s() keywords must be strings", function_name);
    return 0;
#endif
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%s() got an unexpected keyword argument '%s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
    return 0;
}

static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) {
    PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname);
}

static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_mod_PY_LONG_LONG(PY_LONG_LONG a, PY_LONG_LONG b) {
    PY_LONG_LONG r = a % b;
    r += ((r != 0) & ((r ^ b) < 0)) * b;
    return r;
}

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_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_Restore(type, value, tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(type, value, tb);
#endif
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    #if PY_VERSION_HEX < 0x02050000
    if (PyClass_Check(type)) {
    #else
    if (PyType_Check(type)) {
    #endif
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                type = 0;
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) Py_TYPE(type);
            Py_INCREF(type);
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception class must be a subclass of BaseException");
                goto raise_error;
            }
        #endif
    }
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else /* Python 3+ */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *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 = PyEval_CallObject(type, args);
        Py_DECREF(args);
        if (!owned_instance)
            goto bad;
        value = owned_instance;
        if (!PyExceptionInstance_Check(value)) {
            PyErr_Format(PyExc_TypeError,
                         "calling %R should have returned an instance of "
                         "BaseException, not %R",
                         type, Py_TYPE(value));
            goto bad;
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
    if (cause && cause != Py_None) {
        PyObject *fixed_cause;
        if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        }
        else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        }
        else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, long level) {
    PyObject *py_import = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    py_import = __Pyx_GetAttrString(__pyx_b, "__import__");
    if (!py_import)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    #if PY_VERSION_HEX >= 0x02050000
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                /* try package relative import first */
                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);
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0; /* try absolute import on failure */
        }
        #endif
        if (!module) {
            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
    if (level>0) {
        PyErr_SetString(PyExc_RuntimeError, "Relative import is not supported for Python <=2.4.");
        goto bad;
    }
    module = PyObject_CallFunctionObjArgs(py_import,
        name, global_dict, empty_dict, list, NULL);
    #endif
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(py_import);
    Py_XDECREF(empty_dict);
    return module;
}

static CYTHON_INLINE void __Pyx_RaiseImportError(PyObject *name) {
#if PY_MAJOR_VERSION < 3
    PyErr_Format(PyExc_ImportError, "cannot import name %.230s",
                 PyString_AsString(name));
#else
    PyErr_Format(PyExc_ImportError, "cannot import name %S", name);
#endif
}

static CYTHON_INLINE long __Pyx_pow_long(long b, long e) {
    long t = b;
    switch (e) {
        case 3:
            t *= b;
        case 2:
            t *= b;
        case 1:
            return t;
        case 0:
            return 1;
    }
    if (unlikely(e<0)) return 0;
    t = 1;
    while (likely(e)) {
        t *= (b * (e&1)) | ((~e)&1);    /* 1 or b */
        b *= b;
        e >>= 1;
    }
    return t;
}

static CYTHON_INLINE uint64_t __Pyx_pow_uint64_t(uint64_t b, uint64_t e) {
    uint64_t t = b;
    switch (e) {
        case 3:
            t *= b;
        case 2:
            t *= b;
        case 1:
            return t;
        case 0:
            return 1;
    }
    if (unlikely(e<0)) return 0;
    t = 1;
    while (likely(e)) {
        t *= (b * (e&1)) | ((~e)&1);    /* 1 or b */
        b *= b;
        e >>= 1;
    }
    return t;
}

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint64_t(uint64_t val) {
    const uint64_t neg_one = (uint64_t)-1, const_zero = (uint64_t)0;
    const int is_unsigned = const_zero < neg_one;
    if ((sizeof(uint64_t) == sizeof(char))  ||
        (sizeof(uint64_t) == sizeof(short))) {
        return PyInt_FromLong((long)val);
    } else if ((sizeof(uint64_t) == sizeof(int)) ||
               (sizeof(uint64_t) == sizeof(long))) {
        if (is_unsigned)
            return PyLong_FromUnsignedLong((unsigned long)val);
        else
            return PyInt_FromLong((long)val);
    } else if (sizeof(uint64_t) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
        else
            return PyLong_FromLongLong((PY_LONG_LONG)val);
    } else {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        return _PyLong_FromByteArray(bytes, sizeof(uint64_t),
                                     little, !is_unsigned);
    }
}

#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static PyObject *__Pyx_GetStdout(void) {
    PyObject *f = PySys_GetObject((char *)"stdout");
    if (!f) {
        PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
    }
    return f;
}
static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) {
    int i;
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
        PyObject* v;
        if (PyFile_SoftSpace(f, 1)) {
            if (PyFile_WriteString(" ", f) < 0)
                goto error;
        }
        v = PyTuple_GET_ITEM(arg_tuple, i);
        if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
            goto error;
        if (PyString_Check(v)) {
            char *s = PyString_AsString(v);
            Py_ssize_t len = PyString_Size(v);
            if (len > 0 &&
                isspace(Py_CHARMASK(s[len-1])) &&
                s[len-1] != ' ')
                    PyFile_SoftSpace(f, 0);
        }
    }
    if (newline) {
        if (PyFile_WriteString("\n", f) < 0)
            goto error;
        PyFile_SoftSpace(f, 0);
    }
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
}
#else /* Python 3 has a print function */
static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
    PyObject* kwargs = 0;
    PyObject* result = 0;
    PyObject* end_string;
    if (unlikely(!__pyx_print)) {
        __pyx_print = __Pyx_GetAttrString(__pyx_b, "print");
        if (!__pyx_print)
            return -1;
    }
    if (stream) {
        kwargs = PyDict_New();
        if (unlikely(!kwargs))
            return -1;
        if (unlikely(PyDict_SetItemString(kwargs, "file", stream) < 0))
            goto bad;
        if (!newline) {
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                goto bad;
            if (PyDict_SetItemString(kwargs, "end", end_string) < 0) {
                Py_DECREF(end_string);
                goto bad;
            }
            Py_DECREF(end_string);
        }
    } else if (!newline) {
        if (unlikely(!__pyx_print_kwargs)) {
            __pyx_print_kwargs = PyDict_New();
            if (unlikely(!__pyx_print_kwargs))
                return -1;
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                return -1;
            if (PyDict_SetItemString(__pyx_print_kwargs, "end", end_string) < 0) {
                Py_DECREF(end_string);
                return -1;
            }
            Py_DECREF(end_string);
        }
        kwargs = __pyx_print_kwargs;
    }
    result = PyObject_Call(__pyx_print, arg_tuple, kwargs);
    if (unlikely(kwargs) && (kwargs != __pyx_print_kwargs))
        Py_DECREF(kwargs);
    if (!result)
        return -1;
    Py_DECREF(result);
    return 0;
bad:
    if (kwargs != __pyx_print_kwargs)
        Py_XDECREF(kwargs);
    return -1;
}
#endif

#if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    if (PyFile_SoftSpace(f, 0)) {
        if (PyFile_WriteString(" ", f) < 0)
            goto error;
    }
    if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
        goto error;
    if (PyFile_WriteString("\n", f) < 0)
        goto error;
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
    /* the line below is just to avoid C compiler
     * warnings about unused functions */
    return __Pyx_Print(f, NULL, 0);
}
#else /* Python 3 has a print function */
static int __Pyx_PrintOne(PyObject* stream, PyObject *o) {
    int res;
    PyObject* arg_tuple = PyTuple_Pack(1, o);
    if (unlikely(!arg_tuple))
        return -1;
    res = __Pyx_Print(stream, arg_tuple, 1);
    Py_DECREF(arg_tuple);
    return res;
}
#endif

static CYTHON_INLINE PyObject *__Pyx_PyInt_to_py_uint32_t(uint32_t val) {
    const uint32_t neg_one = (uint32_t)-1, const_zero = (uint32_t)0;
    const int is_unsigned = const_zero < neg_one;
    if ((sizeof(uint32_t) == sizeof(char))  ||
        (sizeof(uint32_t) == sizeof(short))) {
        return PyInt_FromLong((long)val);
    } else if ((sizeof(uint32_t) == sizeof(int)) ||
               (sizeof(uint32_t) == sizeof(long))) {
        if (is_unsigned)
            return PyLong_FromUnsignedLong((unsigned long)val);
        else
            return PyInt_FromLong((long)val);
    } else if (sizeof(uint32_t) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)val);
        else
            return PyLong_FromLongLong((PY_LONG_LONG)val);
    } else {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&val;
        return _PyLong_FromByteArray(bytes, sizeof(uint32_t),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE uint32_t __Pyx_PyInt_from_py_uint32_t(PyObject* x) {
    const uint32_t neg_one = (uint32_t)-1, const_zero = (uint32_t)0;
    const int is_unsigned = const_zero < neg_one;
    if (sizeof(uint32_t) == sizeof(char)) {
        if (is_unsigned)
            return (uint32_t)__Pyx_PyInt_AsUnsignedChar(x);
        else
            return (uint32_t)__Pyx_PyInt_AsSignedChar(x);
    } else if (sizeof(uint32_t) == sizeof(short)) {
        if (is_unsigned)
            return (uint32_t)__Pyx_PyInt_AsUnsignedShort(x);
        else
            return (uint32_t)__Pyx_PyInt_AsSignedShort(x);
    } else if (sizeof(uint32_t) == sizeof(int)) {
        if (is_unsigned)
            return (uint32_t)__Pyx_PyInt_AsUnsignedInt(x);
        else
            return (uint32_t)__Pyx_PyInt_AsSignedInt(x);
    } else if (sizeof(uint32_t) == sizeof(long)) {
        if (is_unsigned)
            return (uint32_t)__Pyx_PyInt_AsUnsignedLong(x);
        else
            return (uint32_t)__Pyx_PyInt_AsSignedLong(x);
    } else if (sizeof(uint32_t) == sizeof(PY_LONG_LONG)) {
        if (is_unsigned)
            return (uint32_t)__Pyx_PyInt_AsUnsignedLongLong(x);
        else
            return (uint32_t)__Pyx_PyInt_AsSignedLongLong(x);
    }  else {
        #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_VERSION_HEX < 0x03000000
        if (likely(v) && !PyLong_Check(v)) {
            PyObject *tmp = v;
            v = PyNumber_Long(tmp);
            Py_DECREF(tmp);
        }
        #endif
        if (likely(v)) {
            int one = 1; int is_little = (int)*(unsigned char *)&one;
            unsigned char *bytes = (unsigned char *)&val;
            int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                          bytes, sizeof(val),
                                          is_little, !is_unsigned);
            Py_DECREF(v);
            if (likely(!ret))
                return val;
        }
        #endif
        return (uint32_t)-1;
    }
}

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return ::std::complex< float >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return x + y*(__pyx_t_float_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      __pyx_t_float_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

#if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        float denom = b.real * b.real + b.imag * b.imag;
        z.real = (a.real * b.real + a.imag * b.imag) / denom;
        z.imag = (a.imag * b.real - a.real * b.imag) / denom;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrtf(z.real*z.real + z.imag*z.imag);
          #else
            return hypotf(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
            __pyx_t_float_complex z;
            float r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    float denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(a, a);
                    case 3:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(z, a);
                    case 4:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_absf(a);
                theta = atan2f(a.imag, a.real);
            }
            lnr = logf(r);
            z_r = expf(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cosf(z_theta);
            z.imag = z_r * sinf(z_theta);
            return z;
        }
    #endif
#endif

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return ::std::complex< double >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return x + y*(__pyx_t_double_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      __pyx_t_double_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

#if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_double_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        double denom = b.real * b.real + b.imag * b.imag;
        z.real = (a.real * b.real + a.imag * b.imag) / denom;
        z.imag = (a.imag * b.real - a.real * b.imag) / denom;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrt(z.real*z.real + z.imag*z.imag);
          #else
            return hypot(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex a, __pyx_t_double_complex b) {
            __pyx_t_double_complex z;
            double r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    double denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(a, a);
                    case 3:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(z, a);
                    case 4:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_abs(a);
                theta = atan2(a.imag, a.real);
            }
            lnr = log(r);
            z_r = exp(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cos(z_theta);
            z.imag = z_r * sin(z_theta);
            return z;
        }
    #endif
#endif

static CYTHON_INLINE unsigned char __Pyx_PyInt_AsUnsignedChar(PyObject* x) {
    const unsigned char neg_one = (unsigned char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned char" :
                    "value too large to convert to unsigned char");
            }
            return (unsigned char)-1;
        }
        return (unsigned char)val;
    }
    return (unsigned char)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned short __Pyx_PyInt_AsUnsignedShort(PyObject* x) {
    const unsigned short neg_one = (unsigned short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned short" :
                    "value too large to convert to unsigned short");
            }
            return (unsigned short)-1;
        }
        return (unsigned short)val;
    }
    return (unsigned short)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE unsigned int __Pyx_PyInt_AsUnsignedInt(PyObject* x) {
    const unsigned int neg_one = (unsigned int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(unsigned int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(unsigned int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to unsigned int" :
                    "value too large to convert to unsigned int");
            }
            return (unsigned int)-1;
        }
        return (unsigned int)val;
    }
    return (unsigned int)__Pyx_PyInt_AsUnsignedLong(x);
}

static CYTHON_INLINE char __Pyx_PyInt_AsChar(PyObject* x) {
    const char neg_one = (char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to char" :
                    "value too large to convert to char");
            }
            return (char)-1;
        }
        return (char)val;
    }
    return (char)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE short __Pyx_PyInt_AsShort(PyObject* x) {
    const short neg_one = (short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to short" :
                    "value too large to convert to short");
            }
            return (short)-1;
        }
        return (short)val;
    }
    return (short)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsInt(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE signed char __Pyx_PyInt_AsSignedChar(PyObject* x) {
    const signed char neg_one = (signed char)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed char) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed char)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed char" :
                    "value too large to convert to signed char");
            }
            return (signed char)-1;
        }
        return (signed char)val;
    }
    return (signed char)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed short __Pyx_PyInt_AsSignedShort(PyObject* x) {
    const signed short neg_one = (signed short)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed short) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed short)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed short" :
                    "value too large to convert to signed short");
            }
            return (signed short)-1;
        }
        return (signed short)val;
    }
    return (signed short)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE signed int __Pyx_PyInt_AsSignedInt(PyObject* x) {
    const signed int neg_one = (signed int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(signed int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(signed int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to signed int" :
                    "value too large to convert to signed int");
            }
            return (signed int)-1;
        }
        return (signed int)val;
    }
    return (signed int)__Pyx_PyInt_AsSignedLong(x);
}

static CYTHON_INLINE int __Pyx_PyInt_AsLongDouble(PyObject* x) {
    const int neg_one = (int)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
    if (sizeof(int) < sizeof(long)) {
        long val = __Pyx_PyInt_AsLong(x);
        if (unlikely(val != (long)(int)val)) {
            if (!unlikely(val == -1 && PyErr_Occurred())) {
                PyErr_SetString(PyExc_OverflowError,
                    (is_unsigned && unlikely(val < 0)) ?
                    "can't convert negative value to int" :
                    "value too large to convert to int");
            }
            return (int)-1;
        }
        return (int)val;
    }
    return (int)__Pyx_PyInt_AsLong(x);
}

static CYTHON_INLINE unsigned long __Pyx_PyInt_AsUnsignedLong(PyObject* x) {
    const unsigned long neg_one = (unsigned long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned long");
            return (unsigned long)-1;
        }
        return (unsigned long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned long");
                return (unsigned long)-1;
            }
            return (unsigned long)PyLong_AsUnsignedLong(x);
        } else {
            return (unsigned long)PyLong_AsLong(x);
        }
    } else {
        unsigned long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned long)-1;
        val = __Pyx_PyInt_AsUnsignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_PyInt_AsUnsignedLongLong(PyObject* x) {
    const unsigned PY_LONG_LONG neg_one = (unsigned PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to unsigned PY_LONG_LONG");
            return (unsigned PY_LONG_LONG)-1;
        }
        return (unsigned PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to unsigned PY_LONG_LONG");
                return (unsigned PY_LONG_LONG)-1;
            }
            return (unsigned PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
            return (unsigned PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        unsigned PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (unsigned PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsUnsignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE long __Pyx_PyInt_AsLong(PyObject* x) {
    const long neg_one = (long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to long");
            return (long)-1;
        }
        return (long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to long");
                return (long)-1;
            }
            return (long)PyLong_AsUnsignedLong(x);
        } else {
            return (long)PyLong_AsLong(x);
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long)-1;
        val = __Pyx_PyInt_AsLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE PY_LONG_LONG __Pyx_PyInt_AsLongLong(PyObject* x) {
    const PY_LONG_LONG neg_one = (PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to PY_LONG_LONG");
            return (PY_LONG_LONG)-1;
        }
        return (PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to PY_LONG_LONG");
                return (PY_LONG_LONG)-1;
            }
            return (PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
            return (PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed long __Pyx_PyInt_AsSignedLong(PyObject* x) {
    const signed long neg_one = (signed long)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed long");
            return (signed long)-1;
        }
        return (signed long)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed long");
                return (signed long)-1;
            }
            return (signed long)PyLong_AsUnsignedLong(x);
        } else {
            return (signed long)PyLong_AsLong(x);
        }
    } else {
        signed long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed long)-1;
        val = __Pyx_PyInt_AsSignedLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static CYTHON_INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
    const signed PY_LONG_LONG neg_one = (signed PY_LONG_LONG)-1, const_zero = 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_VERSION_HEX < 0x03000000
    if (likely(PyInt_Check(x))) {
        long val = PyInt_AS_LONG(x);
        if (is_unsigned && unlikely(val < 0)) {
            PyErr_SetString(PyExc_OverflowError,
                            "can't convert negative value to signed PY_LONG_LONG");
            return (signed PY_LONG_LONG)-1;
        }
        return (signed PY_LONG_LONG)val;
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
            if (unlikely(Py_SIZE(x) < 0)) {
                PyErr_SetString(PyExc_OverflowError,
                                "can't convert negative value to signed PY_LONG_LONG");
                return (signed PY_LONG_LONG)-1;
            }
            return (signed PY_LONG_LONG)PyLong_AsUnsignedLongLong(x);
        } else {
            return (signed PY_LONG_LONG)PyLong_AsLongLong(x);
        }
    } else {
        signed PY_LONG_LONG val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (signed PY_LONG_LONG)-1;
        val = __Pyx_PyInt_AsSignedLongLong(tmp);
        Py_DECREF(tmp);
        return val;
    }
}

static 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_GetAttrString(ev, "args");
        Py_DECREF(ev);
        if (likely(args)) {
            value = PyObject_GetItem(args, 0);
            Py_DECREF(args);
        }
        if (unlikely(!value)) {
            __Pyx_ErrRestore(NULL, NULL, NULL);
            Py_INCREF(Py_None);
            value = Py_None;
        }
    }
#endif
    *pvalue = value;
    return 0;
}
#endif
static CYTHON_INLINE
void __Pyx_Generator_ExceptionClear(__pyx_GeneratorObject *self) {
    PyObject *exc_type = self->exc_type;
    PyObject *exc_value = self->exc_value;
    PyObject *exc_traceback = self->exc_traceback;
    self->exc_type = NULL;
    self->exc_value = NULL;
    self->exc_traceback = NULL;
    Py_XDECREF(exc_type);
    Py_XDECREF(exc_value);
    Py_XDECREF(exc_traceback);
}
static CYTHON_INLINE
int __Pyx_Generator_CheckRunning(__pyx_GeneratorObject *gen) {
    if (unlikely(gen->is_running)) {
        PyErr_SetString(PyExc_ValueError,
                        "generator already executing");
        return 1;
    }
    return 0;
}
static CYTHON_INLINE
PyObject *__Pyx_Generator_SendEx(__pyx_GeneratorObject *self, PyObject *value) {
    PyObject *retval;
    assert(!self->is_running);
    if (unlikely(self->resume_label == 0)) {
        if (unlikely(value && value != Py_None)) {
            PyErr_SetString(PyExc_TypeError,
                            "can't send non-None value to a "
                            "just-started generator");
            return NULL;
        }
    }
    if (unlikely(self->resume_label == -1)) {
        PyErr_SetNone(PyExc_StopIteration);
        return NULL;
    }
    if (value) {
#if CYTHON_COMPILING_IN_PYPY
#else
        /* Generators always return to their most recent caller, not
         * necessarily their creator. */
        if (self->exc_traceback) {
            PyThreadState *tstate = PyThreadState_GET();
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_XINCREF(tstate->frame);
            assert(f->f_back == NULL);
            f->f_back = tstate->frame;
        }
#endif
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
    } else {
        __Pyx_Generator_ExceptionClear(self);
    }
    self->is_running = 1;
    retval = self->body((PyObject *) self, value);
    self->is_running = 0;
    if (retval) {
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
#if CYTHON_COMPILING_IN_PYPY
#else
        /* Don't keep the reference to f_back any longer than necessary.  It
         * may keep a chain of frames alive or it could create a reference
         * cycle. */
        if (self->exc_traceback) {
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_CLEAR(f->f_back);
        }
#endif
    } else {
        __Pyx_Generator_ExceptionClear(self);
    }
    return retval;
}
static CYTHON_INLINE
PyObject *__Pyx_Generator_FinishDelegation(__pyx_GeneratorObject *gen) {
    PyObject *ret;
    PyObject *val = NULL;
    __Pyx_Generator_Undelegate(gen);
    __Pyx_PyGen_FetchStopIterationValue(&val);
    ret = __Pyx_Generator_SendEx(gen, val);
    Py_XDECREF(val);
    return ret;
}
static PyObject *__Pyx_Generator_Next(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        ret = Py_TYPE(yf)->tp_iternext(yf);
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        return __Pyx_Generator_FinishDelegation(gen);
    }
    return __Pyx_Generator_SendEx(gen, Py_None);
}
static PyObject *__Pyx_Generator_Send(PyObject *self, PyObject *value) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Send(yf, value);
        } else {
            if (value == Py_None)
                ret = PyIter_Next(yf);
            else
                ret = PyObject_CallMethod(yf, (char*)"send", (char*)"O", 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_GetAttrString(yf, "close");
        if (unlikely(!meth)) {
            if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                PyErr_WriteUnraisable(yf);
            }
            PyErr_Clear();
        } else {
            retval = PyObject_CallFunction(meth, NULL);
            Py_DECREF(meth);
            if (!retval)
                err = -1;
        }
        gen->is_running = 0;
    }
    Py_XDECREF(retval);
    return err;
}
static PyObject *__Pyx_Generator_Close(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject *retval, *raised_exception;
    PyObject *yf = gen->yieldfrom;
    int err = 0;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        Py_INCREF(yf);
        err = __Pyx_Generator_CloseIter(gen, yf);
        __Pyx_Generator_Undelegate(gen);
        Py_DECREF(yf);
    }
    if (err == 0)
#if PY_VERSION_HEX < 0x02050000
        PyErr_SetNone(PyExc_StopIteration);
#else
        PyErr_SetNone(PyExc_GeneratorExit);
#endif
    retval = __Pyx_Generator_SendEx(gen, NULL);
    if (retval) {
        Py_DECREF(retval);
        PyErr_SetString(PyExc_RuntimeError,
                        "generator ignored GeneratorExit");
        return NULL;
    }
    raised_exception = PyErr_Occurred();
    if (!raised_exception
        || raised_exception == PyExc_StopIteration
#if PY_VERSION_HEX >= 0x02050000
        || raised_exception == PyExc_GeneratorExit
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit)
#endif
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration))
    {
        if (raised_exception) PyErr_Clear();      /* ignore these errors */
        Py_INCREF(Py_None);
        return Py_None;
    }
    return NULL;
}
static PyObject *__Pyx_Generator_Throw(PyObject *self, PyObject *args) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject *typ;
    PyObject *tb = NULL;
    PyObject *val = NULL;
    PyObject *yf = gen->yieldfrom;
    if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
        return NULL;
    if (unlikely(__Pyx_Generator_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        Py_INCREF(yf);
#if PY_VERSION_HEX >= 0x02050000
        if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) {
            int err = __Pyx_Generator_CloseIter(gen, yf);
            Py_DECREF(yf);
            __Pyx_Generator_Undelegate(gen);
            if (err < 0)
                return __Pyx_Generator_SendEx(gen, NULL);
            goto throw_here;
        }
#endif
        gen->is_running = 1;
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Throw(yf, args);
        } else {
            PyObject *meth = PyObject_GetAttrString(yf, "throw");
            if (unlikely(!meth)) {
                Py_DECREF(yf);
                if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                    gen->is_running = 0;
                    return NULL;
                }
                PyErr_Clear();
                __Pyx_Generator_Undelegate(gen);
                gen->is_running = 0;
                goto throw_here;
            }
            ret = PyObject_CallObject(meth, args);
            Py_DECREF(meth);
        }
        gen->is_running = 0;
        Py_DECREF(yf);
        if (!ret) {
            ret = __Pyx_Generator_FinishDelegation(gen);
        }
        return ret;
    }
throw_here:
    __Pyx_Raise(typ, val, tb, NULL);
    return __Pyx_Generator_SendEx(gen, NULL);
}
static int __Pyx_Generator_traverse(PyObject *self, visitproc visit, void *arg) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    Py_VISIT(gen->closure);
    Py_VISIT(gen->classobj);
    Py_VISIT(gen->yieldfrom);
    Py_VISIT(gen->exc_type);
    Py_VISIT(gen->exc_value);
    Py_VISIT(gen->exc_traceback);
    return 0;
}
static int __Pyx_Generator_clear(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    Py_CLEAR(gen->closure);
    Py_CLEAR(gen->classobj);
    Py_CLEAR(gen->yieldfrom);
    Py_CLEAR(gen->exc_type);
    Py_CLEAR(gen->exc_value);
    Py_CLEAR(gen->exc_traceback);
    return 0;
}
static void __Pyx_Generator_dealloc(PyObject *self) {
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    PyObject_GC_UnTrack(gen);
    if (gen->gi_weakreflist != NULL)
        PyObject_ClearWeakRefs(self);
    PyObject_GC_Track(self);
    if (gen->resume_label > 0) {
        Py_TYPE(gen)->tp_del(self);
        if (self->ob_refcnt > 0)
            return;                     /* resurrected.  :( */
    }
    PyObject_GC_UnTrack(self);
    __Pyx_Generator_clear(self);
    PyObject_GC_Del(gen);
}
static void __Pyx_Generator_del(PyObject *self) {
    PyObject *res;
    PyObject *error_type, *error_value, *error_traceback;
    __pyx_GeneratorObject *gen = (__pyx_GeneratorObject *) self;
    if (gen->resume_label <= 0)
        return ;
    assert(self->ob_refcnt == 0);
    self->ob_refcnt = 1;
    __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);
    /* Undo the temporary resurrection; can't use DECREF here, it would
     * cause a recursive call.
     */
    assert(self->ob_refcnt > 0);
    if (--self->ob_refcnt == 0)
        return; /* this is the normal path out */
    /* close() resurrected it!  Make it look like the original Py_DECREF
     * never happened.
     */
    {
        Py_ssize_t refcnt = self->ob_refcnt;
        _Py_NewReference(self);
        self->ob_refcnt = refcnt;
    }
#if CYTHON_COMPILING_FOR_CPYTHON
    assert(PyType_IS_GC(self->ob_type) &&
           _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
    /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
     * we need to undo that. */
    _Py_DEC_REFTOTAL;
#endif
    /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object
     * chain, so no more to do there.
     * If COUNT_ALLOCS, the original decref bumped tp_frees, and
     * _Py_NewReference bumped tp_allocs:  both of those need to be
     * undone.
     */
#ifdef COUNT_ALLOCS
    --Py_TYPE(self)->tp_frees;
    --Py_TYPE(self)->tp_allocs;
#endif
}
static PyMemberDef __pyx_Generator_memberlist[] = {
    {(char *) "gi_running",
#if PY_VERSION_HEX >= 0x02060000
     T_BOOL,
#else
     T_BYTE,
#endif
     offsetof(__pyx_GeneratorObject, is_running),
     READONLY,
     NULL},
    {0, 0, 0, 0, 0}
};
static PyMethodDef __pyx_Generator_methods[] = {
    {__Pyx_NAMESTR("send"), (PyCFunction) __Pyx_Generator_Send, METH_O, 0},
    {__Pyx_NAMESTR("throw"), (PyCFunction) __Pyx_Generator_Throw, METH_VARARGS, 0},
    {__Pyx_NAMESTR("close"), (PyCFunction) __Pyx_Generator_Close, METH_NOARGS, 0},
    {0, 0, 0, 0}
};
static PyTypeObject __pyx_GeneratorType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    __Pyx_NAMESTR("generator"),         /*tp_name*/
    sizeof(__pyx_GeneratorObject),      /*tp_basicsize*/
    0,                                  /*tp_itemsize*/
    (destructor) __Pyx_Generator_dealloc,/*tp_dealloc*/
    0,                                  /*tp_print*/
    0,                                  /*tp_getattr*/
    0,                                  /*tp_setattr*/
#if PY_MAJOR_VERSION < 3
    0,                                  /*tp_compare*/
#else
    0,                                  /*reserved*/
#endif
    0,                                   /*tp_repr*/
    0,                                  /*tp_as_number*/
    0,                                  /*tp_as_sequence*/
    0,                                  /*tp_as_mapping*/
    0,                                  /*tp_hash*/
    0,                                  /*tp_call*/
    0,                                  /*tp_str*/
    0,                                  /*tp_getattro*/
    0,                                  /*tp_setattro*/
    0,                                  /*tp_as_buffer*/
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags*/
    0,                                  /*tp_doc*/
    (traverseproc) __Pyx_Generator_traverse,   /*tp_traverse*/
    0,                                  /*tp_clear*/
    0,                                  /*tp_richcompare*/
    offsetof(__pyx_GeneratorObject, gi_weakreflist), /* tp_weaklistoffse */
    0,                                  /*tp_iter*/
    (iternextfunc) __Pyx_Generator_Next, /*tp_iternext*/
    __pyx_Generator_methods,            /*tp_methods*/
    __pyx_Generator_memberlist,         /*tp_members*/
    0,                                  /*tp_getset*/
    0,                                  /*tp_base*/
    0,                                  /*tp_dict*/
    0,                                  /*tp_descr_get*/
    0,                                  /*tp_descr_set*/
    0,                                  /*tp_dictoffset*/
    0,                                  /*tp_init*/
    0,                                  /*tp_alloc*/
    0,                                  /*tp_new*/
    0,                                  /*tp_free*/
    0,                                  /*tp_is_gc*/
    0,                                  /*tp_bases*/
    0,                                  /*tp_mro*/
    0,                                  /*tp_cache*/
    0,                                  /*tp_subclasses*/
    0,                                  /*tp_weaklist*/
    __Pyx_Generator_del,                /*tp_del*/
#if PY_VERSION_HEX >= 0x02060000
    0,                                  /*tp_version_tag*/
#endif
};
static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body,
                                                  PyObject *closure) {
    __pyx_GeneratorObject *gen =
        PyObject_GC_New(__pyx_GeneratorObject, &__pyx_GeneratorType_type);
    if (gen == NULL)
        return NULL;
    gen->body = body;
    gen->closure = closure;
    Py_XINCREF(closure);
    gen->is_running = 0;
    gen->resume_label = 0;
    gen->classobj = NULL;
    gen->yieldfrom = NULL;
    gen->exc_type = NULL;
    gen->exc_value = NULL;
    gen->exc_traceback = NULL;
    gen->gi_weakreflist = NULL;
    PyObject_GC_Track(gen);
    return gen;
}
static int __pyx_Generator_init(void) {
    __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr;
    __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
    if (PyType_Ready(&__pyx_GeneratorType_type)) {
        return -1;
    }
    __pyx_GeneratorType = &__pyx_GeneratorType_type;
    return 0;
}

static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        #if PY_VERSION_HEX < 0x02050000
        return PyErr_Warn(NULL, message);
        #else
        return PyErr_WarnEx(NULL, message, 1);
        #endif
    }
    return 0;
}

#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    py_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,
            "%s.%s is not a type object",
            module_name, class_name);
        goto bad;
    }
    if (!strict && (size_t)((PyTypeObject *)result)->tp_basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility",
            module_name, class_name);
        #if PY_VERSION_HEX < 0x02050000
        if (PyErr_Warn(NULL, warning) < 0) goto bad;
        #else
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
        #endif
    }
    else if ((size_t)((PyTypeObject *)result)->tp_basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%s.%s 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 void* __Pyx_GetVtable(PyObject *dict) {
    void* ptr;
    PyObject *ob = PyMapping_GetItemString(dict, (char *)"__pyx_vtable__");
    if (!ob)
        goto bad;
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
    ptr = PyCapsule_GetPointer(ob, 0);
#else
    ptr = PyCObject_AsVoidPtr(ob);
#endif
    if (!ptr && !PyErr_Occurred())
        PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
    Py_DECREF(ob);
    return ptr;
bad:
    Py_XDECREF(ob);
    return NULL;
}

static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = (start + end) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, new_max*sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        0,            /*int argcount,*/
        0,            /*int kwonlyargcount,*/
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,      /*int firstlineno,*/
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_globals = 0;
    PyFrameObject *py_frame = 0;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = py_line;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else  /* Python 3+ has unicode identifiers */
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}


/* Type Conversion Functions */

static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}

static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_VERSION_HEX < 0x03000000
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return Py_INCREF(x), x;
  m = Py_TYPE(x)->tp_as_number;
#if PY_VERSION_HEX < 0x03000000
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_VERSION_HEX < 0x03000000
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%s__ returned non-%s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}

static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject* x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}

static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
#if PY_VERSION_HEX < 0x02050000
   if (ival <= LONG_MAX)
       return PyInt_FromLong((long)ival);
   else {
       unsigned char *bytes = (unsigned char *) &ival;
       int one = 1; int little = (int)*(unsigned char*)&one;
       return _PyLong_FromByteArray(bytes, sizeof(size_t), little, 0);
   }
#else
   return PyInt_FromSize_t(ival);
#endif
}

static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject* x) {
   unsigned PY_LONG_LONG val = __Pyx_PyInt_AsUnsignedLongLong(x);
   if (unlikely(val == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred())) {
       return (size_t)-1;
   } else if (unlikely(val != (unsigned PY_LONG_LONG)(size_t)val)) {
       PyErr_SetString(PyExc_OverflowError,
                       "value too large to convert to size_t");
       return (size_t)-1;
   }
   return (size_t)val;
}


#endif /* Py_PYTHON_H */
